Input and output with human-readable text files
import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; public class InputOutputDemo { public static void main(String[] a) throws Exception { PrintWriter pwr = new PrintWriter(new FileWriter("java2s.txt")); pwr.print(4711); pwr.print(' '); pwr.print("Java Source and Support at www.java2s.com"); pwr.close(); StreamTokenizer stok = new StreamTokenizer(new FileReader("java2s.txt")); int tok = stok.nextToken(); while (tok != StreamTokenizer.TT_EOF) { System.out.println(stok.sval); tok = stok.nextToken(); } } }