// Filename TrivialFileDemo.java. // Read a text file called "test.txt" and output to // the terminal. // // Written for JFL Book Chapter 12. // Fintan Culwin, V 0.1, Jan 1997. // Modified by X. Meng using some compatible features and output file import java.io.*; class TrivialFileDemo { public static void main(String args[]) { DataInputStream in; PrintStream out; try { in = new DataInputStream( new FileInputStream( "test.txt")); out = new PrintStream ( new FileOutputStream( "test.out")); String line = in.readLine(); while ( line != null ) { System.out.println(line); out.println(line); line = in.readLine(); } // end while in.close(); out.close(); } catch ( java.io.IOException exception) { if ( exception instanceof FileNotFoundException) { System.out.println( "A file called test.txt could not be found, \n" + "or could not be opened.\n" + "Please investigate and try again."); } } // End try/ catch block. } // end main. } // End class.