Saving to a TXT file

United States
January 25, 2009 2:42pm CST
I'm sure its possible to save the output of a java program into a txt file and then read it back in. I know you can in C++ (and i know how), but how do you do it in java? I think its called serialization...maybe? idk... Thanks!
1 response
• India
25 Jan 09
import java.io.*; class FileOutputDemo { public static void main(String args[]) { FileOutputStream out; // declare a file output object PrintStream p; // declare a print stream object try { // Create a new file output stream // connected to "myfile.txt" out = new FileOutputStream("myfile.txt"); // Connect print stream to the output stream p = new PrintStream( out ); p.println ("This is written to a file"); p.close(); } catch (Exception e) { System.err.println ("Error writing to file"); } } }
• India
27 Feb 09
thanks for the program
• South Africa
1 Mar 09
Damn java. I havnt seen that in ages. My mind is bugged by C++ nowadays. Hahah. Viva to all the java developers viva!!!!