将System.out输出在控制台的信息保存在文件中(未测试)

来源:互联网 发布:枭龙战斗机知乎 编辑:程序博客网 时间:2024/06/05 09:47
将当前项目的System.out的输出保存在当前项目下的system.out.txt中
           //1.获取项目的目录            Path path = Paths.get(".");            Path resolve = path.resolve("system.out.txt");            System.out.println(resolve.toAbsolutePath().normalize().toString());            //2. 设置            if (resolve !=null) {                //not the best way to debug                OutputStream output = new FileOutputStream(resolve.toAbsolutePath().normalize().toString());                PrintStream printOut = new PrintStream(output);                System.setOut(printOut);            }            //3.测试 system.out.txt中是否有该信息            System.out.println(resolve.toAbsolutePath().normalize().toString())
0 0
原创粉丝点击