Simple Java question

SONYFX

Senior member
May 14, 2003
403
0
0
my program out puts some strings to the command line, if I want to put those stuff into a file, what should I put in my main??

---------------------

 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Instead of sending it to system.out, do println() to a printwriter, wrapping a filewriter (or some combination, I can never remember the correct ones without looking at the JavaDocs).

If you're looking for a quicker fix, re-direct the output using ">" in the command line, into a file.
java progmain > filename.

-Josh
 

chsh1ca

Golden Member
Feb 17, 2003
1,179
0
0
The J2SE SDK docs have your answers. Specifically read up on FileWriter, and File.
Brief synopsis:
File outputFile = new File("filename");
outputFile.createNewFile();
FileWriter fw = new FileWriter(outputFile);
fw.write("Your Text Here");