System.out.println to text file

后端 未结 3 571
南旧
南旧 2020-12-21 04:06

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: \" + Syst         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 04:34

    You can do,

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

    Then any println statement will go into the file.

提交回复
热议问题