Java output console error message to file?
12,825
Solution 1
Add:
System.setErr(out);
at the end.
Solution 2
There is also a System.setErr()
call to redirect stderr.
Solution 3
Solution 4
You're currently redirecting the standard output stream to a file. To redirect the standard error stream use
System.setErr(out);
Author by
Dan_Dan_Man
Updated on July 29, 2022Comments
-
Dan_Dan_Man almost 2 years
I have a simple piece of code that outputs console text to a text file in Java:
PrintStream out = new PrintStream(new FileOutputStream("test2_output.txt")); System.setOut(out);
However I require this text file to contain the error messages that is produced in the console but they are not included.
How do I do this?
-
Dan_Dan_Man about 12 yearsThanks very much. Did the job perfectly. I can't believe I couldn't find this statement anywhere on Google.