import java.io.FileOutputStream; import java.io.PrintStream; import java.io.FileNotFoundException; import java.io.IOException; public class FileOutputStreamDemo { public static void main(String[] args) { try { FileOutputStream s = new FileOutputStream("outfile.txt"); s.write('A'); //A FileOutputStream has no println method. PrintStream stream = new PrintStream(s); stream.println("This is the output file."); stream.close(); } catch (FileNotFoundException e) { //file can't be created or opened System.err.println(e.getMessage()); } catch (IOException e) { System.err.println(e.getMessage()); } } }