public void printFileContents() throws FileNotFoundException, IOException { String filename = JOptionPane.showInputDialog("Enter filename"); BufferedReader input = new BufferedReader(new FileReader(filename)); String line = input.readLine(); while (line != null) { System.out.println(line); line = input.readLine(); } input.close(); }
File
objects represent abstract path names independently
of the operating system
File f = new File("/home/ferrer/jett/io.html");
File
object may be used in place of a String
filename with FileReader
and FileWriter