开发者

Append java console to file

开发者 https://www.devze.com 2023-04-13 02:59 出处:网络
I use the following lines to redirect my console output to a file : PrintStream stream = new PrintStream(\"console.log\");

I use the following lines to redirect my console output to a file :

  PrintStream stream = new PrintStream("console.log");
  System.setOut(stre开发者_如何学运维am);

Now the file is overwritten with every start of the application, thus losing all previous entries, but i´d like it to append every session to a persistent console logfile. Is it possible ?


This should work:

PrintStream stream = new PrintStream(new FileOutputStream("console.log", true));


Set the second argument to true.

 try {
  BufferedWriter out = new BufferedWriter(new FileWriter("file.txt", true));
  out.close();
  } catch (Exception e) {}
0

精彩评论

暂无评论...
验证码 换一张
取 消