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