// File Input output example // By Daryl Moulder, updated by Heather McCarthy 22/8/98 import java.io.*; public class NewTextFileIO { public static void main(String args[]) { String myFilePath = "test.txt"; try { // writing to file FileWriter fw = new FileWriter(myFilePath); PrintWriter pw = new PrintWriter(fw); pw.println("Testing some characters and numbers " + 1234); pw.close(); // closes FileWriter as well // reading from file FileReader fr = new FileReader(myFilePath); BufferedReader br = new BufferedReader(fr); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); // also closes the FileReader by calling // 'fr.close()' } catch(IOException e) { System.out.println("File error " + e); } catch(Exception e) { } } }