[ACCEPTED]-How can we redirect a Java program console output to multiple files?-eclipse

Accepted answer
Score: 175

Go to run as and choose Run Configurations -> Common and in the 2 Standard Input and Output you can choose 1 a File also.

Score: 11

You could use a "variable" inside the output 8 filename, for example:



Returns 7 the current system time formatted as yyyyMMdd_HHmm. An 6 optional argument can be used to provide 5 alternative formatting. The argument must 4 be valid pattern for java.util.SimpleDateFormat.

Or 3 you can also use a system_property or an 2 env_var to specify something dynamic (either 1 one needs to be specified as arguments)

Score: 8

You can set the output of System.out programmatically 9 by doing:

System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("/location/to/console.out")), true));


Due to the fact that this 8 solution is based on a PrintStream, we can enable autoFlush, but 7 according to the docs:

autoFlush - A boolean; if 6 true, the output buffer will be flushed whenever 5 a byte array is written, one of the println 4 methods is invoked, or a newline character 3 or byte ('\n') is written

So if a new line 2 isn't written, remember to System.out.flush() manually.

(Thanks 1 Robert Tupelo-Schneck)

Score: 1

To solve the problem I use ${string_prompt} variable. It 4 shows a input dialog when application runs. I 3 can set the date/time manually at that dialog.

  1. Move 2 cursor at the end of file path. enter image description here

  2. Click variables 1 and select string_prompt enter image description here

  3. Select Apply and Run enter image description here enter image description here

Score: 0

We can do this by setting out variable of 7 System class in the following way

System.setOut(new 6 PrintStream(new FileOutputStream("Path 5 to output file"))). Also You need to 4 close or flush 'out'(System.out.close() or 3 System.out.flush()) variable so that you 2 don't end up missing some output.

Source 1 : http://xmodulo.com/how-to-save-console-output-to-file-in-eclipse.html

More Related questions