- If you want to tell Java that you intend to work with file input or
file output streams, then include the following line in your program:
import java.io.*;
- If you want to write to an output file, then instantiate the following
pattern:
FileOutputStream stream variable
= new FileOutputStream(file specification);
PrintWriter printer variable
= new PrintWriter(stream variable);
- If you want to write data to a
PrintWriter instance,
then instantiate one of the following patterns:
print writer.print(information to be printed);
print writer.println(information to be printed);
- If you have finished writing to a file stream via a print writer, then flush
the print writer and close the file by instantiating the following patterns:
print writer variable.flush();
file stream variable.close();