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\"))
Add:
System.setErr(out);
at the end.
There is also a System.setErr()
call to redirect stderr.
Try:
PrintStream pst = new PrintStream("Text.txt");
System.setOut(pst);
System.setErr(pst);
System.out.println("Hello, Finally I've printed output to file..");
You're currently redirecting the standard output stream to a file. To redirect the standard error stream use
System.setErr(out);
System.setErr(out)