import java.io.*; public class FileOutputStreamTest { public static void main(String args[]) { try { FileOutputStream out=new FileOutputStream("myFile.dat"); out.write('H'); out.write(69); out.write(76); out.write('L'); out.write('O'); out.write('!'); out.close(); }catch(FileNotFoundException e) { System.out.println("Error:Cannot open file for writing."); }catch(IOException e) { System.out.println("Error:Cannot write to file."); } } } import java.io.*; public class FileInputStreamTest { public static void main(String args[]) { try { FileInputStream in=new FileInputStream("myFile.dat"); while(in.available()>0) System.out.print(in.read() +""); in.close(); }catch(FileNotFoundException e) { System.out.println("Error:Cannot open file for reading."); }catch(EOFException e) { System.out.println("Error:EOF encouraged,file may be corrupted."); }catch(IOException e) { System.out.println("Error:Cannot read from file."); } } }