// FileIO.java -- open a file and display the first few lines import java.io.*; class FileIO { public static void main(String[] args) throws Exception { // create an object representing the file File f = new File(args[0]); // wrap it with classes for convenient access BufferedReader r = new BufferedReader(new FileReader(f)); // display filename and first few lines System.out.println(f.getAbsolutePath()); String x; int n = 0; while ((n < 10) && (x = r.readLine()) != null) { ++n; System.out.println(x); } // close resources r.close(); } }