I'd like to keep the console displaying the output but also keep it in a textfile as a log. Is there any way to do this? I tried doing this:
PrintStream printStream = new PrintStream(new FileOutputStream(locations[0][0] + "-" + locations[0][1] + "-output.txt"));
System.setOut(printStream);
But it doesn't display the output in the console anymore and it saves it in the project directory. Is there a way to do both?
You need to use a stream which writes to two destination streams (file and stdio). For example, use Apache's
TeeOutputStream
:Another alternative (out of the JAVA scope) is to use the *nix
tee
tool: