【问题标题】:How to save all the System.out.println present in the code in a .txt file? [duplicate]如何将代码中存在的所有 System.out.println 保存在 .txt 文件中? [复制]
【发布时间】:2020-05-01 21:33:31
【问题描述】:

运行我的代码,我想将所有 System.out.println() 保存在一个文件中。

例如:

System.out.println("Save this!");

我需要一个 .txt 文件,其中存储了字符串“保存这个!”。

有人可以帮助我吗?

问候,

弗朗切斯科钟楼

【问题讨论】:

标签: java json selenium file automation


【解决方案1】:

使用它来将控制台写入文件。

PrintStream out = new PrintStream(
        new FileOutputStream("output.txt", true), true);
System.setOut(out);

输出文件将在项目的根目录中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    相关资源
    最近更新 更多