/* TestFile1.java CIS 111 October 8, 2007 Demonstrates sequential file access. This program takes whatever the user types in and writes it to a file line-by-line. */ public class TestFile1 extends CIS111App { public static void main(String[] args) { // open file for writing SequentialFile fileout = new SequentialFile("files1.txt", FileMode.OUTPUT); // loop to get input from user and write to file // (notice use of priming read) String strIn = getString("Enter line (QUIT to exit): "); while (!strIn.equalsIgnoreCase("QUIT")) { fileout.writeln(strIn); strIn = getString("Enter line (QUIT to exit): "); } // close output file fileout.close(); // now let's read back what's in the file SequentialFile filein = new SequentialFile("files1.txt", FileMode.INPUT); println("Here's what is in the file: "); // loop to read and display data from file while (!filein.eof()) { String line = filein.readString(); println(line); } // close input file filein.close(); } }