/* * TestFile.java * * Created on April 18, 2003, 12:40 PM * Demonstrates finding out info about a file */ package simplefile; import java.io.File; import java.io.*; /** * * @author mike */ public class ReadNEcho { /** Creates a new instance of TestFile */ public ReadNEcho() { } /** * @param args the command line arguments */ // Plan 0 - don't really care what's in the file - just show that I can get it out public static void main(String[] args) { // second way - with just file name - has to be in expected folder // default with forte is bin folder insider where Forte was installed String myFilename = "traceCSN.txt"; File res = new File(myFilename); boolean there = res.exists(); // now ready to work with file System.out.println("Does file exist? " + there); FileReader mfr = null; if (there) { System.out.println("File size: " + res.length()); try { mfr = new FileReader(res); } catch (FileNotFoundException noWay) { System.out.println("No way! Can't get here - I check first"); } // buffered reader wraps around file reader BufferedReader mbr = new BufferedReader(mfr); String line = null; for (int cnt = 0; cnt < 10000; cnt++) { try { // get a line at a time line = mbr.readLine(); } catch (IOException ioex) { System.out.println("read failed" + ioex); break; } // when file ends readLine will return null so we could cut off based on that System.out.println("line " + (cnt+1) + ": " + line); } } System.exit(0); } }