Not as elegant as redirecting stdout:
import
java.io.FileOutputStream;
import
java.io.PrintStream;
System.setOut(
new
PrintStream(
new
FileOutputStream(
"output.txt"
)));
System.out.println(
"This is test output"
);
Conservative. Idaho. Software engineer. Historian. Trying to prevent Idiocracy from becoming a documentary.
Email complaints/requests about copyright infringement to clayton @ claytoncramer.com. Reminder: the last copyright troll that bothered me went bankrupt.
import
java.io.FileOutputStream;
import
java.io.PrintStream;
System.setOut(
new
PrintStream(
new
FileOutputStream(
"output.txt"
)));
System.out.println(
"This is test output"
);
See this Stack Overflow answer: https://stackoverflow.com/questions/5714053/how-can-we-redirect-a-java-program-console-output-to-multiple-files
ReplyDeleteI've fought with Eclipse many times, and have pretty much given up trying.
ReplyDeleteHave you tried VS Code?
I followed those instructions and the required fields did not appear. There may be a settings field required to make it appear. I solved the problem another way.
ReplyDeleteStrange--I hadn't tried it out before but I just did and it worked. (the instructions, now that I tried them, are...spare.)
ReplyDeleteI chose Run | Run Configurations from the menu, picked the Common tab on the right, and down near the bottom there was a checkbox next to the text "Output File:", with a textbox to the right. To get it to work I couldn't just type in a file name, I had to click the File System button and type a file name in the standard Windows File Save dialog. I also had to check the checkbox. (I see there's an Append checkbox below that, but I didn't check it--without it, it empties the file on each run.)
I tried Eclipse 2020-03 and 4.5.2.
Thanks Rick. I did not scroll far enough down in that window.
ReplyDelete