System.out.println到文本文件 [英] System.out.println to text file

查看:127
本文介绍了System.out.println到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种获取System.out.println文本并将其保存在.txt文件中的方法,例如:

I was searching a way to get System.out.println texts and save them on a .txt file, for example:

    System.out.println("Java vendor: " + System.getProperty("java.vendor"));
    System.out.println("Operating System architecture: " + System.getProperty("os.arch"));
    System.out.println("Java version: " + System.getProperty("java.version"));
    System.out.println("Operating System: " + System.getProperty("os.name"));
    System.out.println("Operating System Version: " + System.getProperty("os.version"));
    System.out.println("Java Directory: " + System.getProperty("java.home"));

我要输出一个 .txt 文件,有什么想法吗?谢谢

I want a .txt file to the output, any ideas? Thank you

推荐答案

您可以做到,

PrintStream fileStream = new PrintStream("filename.txt");
System.setOut(fileStream);

然后所有println语句都将进入文件.

Then any println statement will go into the file.

这篇关于System.out.println到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆