/* * File: BufferedTextIOTest.java * * Buffered character stream I/O with BufferedReader * and BufferedWriter classes * * Copyright: Northeast Parallel Architectures Center * */ import java.io.IOException; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.PrintWriter; import java.io.FileReader; import java.io.BufferedReader; public class BufferedTextIOTest { public static void main( String args[] ) throws IOException { String line; // for input String filename = "BufferedTextIOTest.dat"; String address[] = { "Northeast Parallel Architectures Center", "111 College Place", "Syracuse University", "Syracuse, NY 13244-4100" }; PrintWriter out = new PrintWriter( new BufferedWriter( new FileWriter( filename ) ) ); // a character stream System.out.println( "Writing..." ); for ( int i = 0; i < address.length; i++ ) { out.println( address[i] ); } out.close(); BufferedReader in = new BufferedReader( new FileReader( filename ) ); // a character stream System.out.println( "Reading..." ); while ( ( line = in.readLine() ) != null ) { System.out.println( line ); } in.close(); } }