在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

将System.out输出在控制台的信息保存在文件中

2016-12-20 13:16| 发布者: zhangjf| 查看: 572| 评论: 0

摘要: 将当前项目的System.out的输出保存在当前项目下的system.out.txt中 //1.获取项目的目录 Path path = Paths.get(.); Path resolve = path.resolve(system.out.txt); ...
将当前项目的System.out的输出保存在当前项目下的system.out.txt中
  1. //1.获取项目的目录
  2. Path path = Paths.get(".");
  3. Path resolve = path.resolve("system.out.txt");
  4. System.out.println(resolve.toAbsolutePath().normalize().toString());
  5. //2. 设置
  6. if (resolve !=null) {
  7. //not the best way to debug
  8. OutputStream output = new FileOutputStream(resolve.toAbsolutePath().normalize().toString());
  9. PrintStream printOut = new PrintStream(output);
  10. System.setOut(printOut);
  11. }
  12. //3.测试 system.out.txt中是否有该信息
  13. System.out.println(resolve.toAbsolutePath().normalize().toString());
复制代码

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-7-8 13:26

Copyright 2015-2025 djqfx

返回顶部