/** * FileTest --- reads strings from a file and prints them out. * @author Blanca J. Polo */ import java.io.*; class FileTest{ /** * FileTest Reads the contents of a file and prints it to the screen * We use a while loop to iterate through the file because we do not * know if the file is empty or has one or many entries. * @param arg A string array containing the command line arguments. * @return No return value. * @exception Exception If the file is not found. */ public static void main (String arg[ ]) throws Exception{ try{ File f = new File("file.txt"); FileInputStream fis = new FileInputStream(f); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); String s = ""; s = br.readLine( ); while(s != null){ System.out.println("***" + s); s = br.readLine( ); } } catch(FileNotFoundException fnfe){ System.out.println("File not found"); } } //main } // class