Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append java console to file

Tags:

java

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

  PrintStream stream = new PrintStream("console.log");
  System.setOut(stream);

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 ?

like image 311
Jannis Alexakis Avatar asked Apr 13 '26 16:04

Jannis Alexakis


1 Answers

This should work:

PrintStream stream = new PrintStream(new FileOutputStream("console.log", true));
like image 178
Michael Borgwardt Avatar answered Apr 16 '26 06:04

Michael Borgwardt