[url]http://my.oschina.net/ordiychen/blog/600419[/url]
//1.获取项目的目录
Path path = Paths.get(".");
Path resolve = path.resolve("system.out.txt");
System.out.println(resolve.toAbsolutePath().normalize().toString());
//2. 设置
if (level.getStandardLevel().intLevel() == 600) {
//not the best way to debug
OutputStream output = new FileOutputStream(resolve.toAbsolutePath().normalize().toString());
PrintStream printOut = new PrintStream(output);
System.setOut(printOut);
}
System.out.println(resolve.toAbsolutePath().normalize().toString());//3.测试 system.out.txt中是否有该信息
本文详细介绍了如何在Java中通过设置文件输出流来将系统输出信息写入指定文件,并通过示例代码展示了实现过程。
979

被折叠的 条评论
为什么被折叠?



