Jannis Alexakis
Jannis Alexakis

Reputation: 1319

Append java console to file

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 ?

Upvotes: 3

Views: 1492

Answers (2)

Mob
Mob

Reputation: 11098

Set the second argument to true.

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

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346250

This should work:

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

Upvotes: 7

Related Questions