// Version of the file reading program that // repeatedly appends to a string. // (Slow) import java.io.*; class StringReader { String string = ""; public void append(char c) { string += c; } public String toString() { return string; } } public class CopyString { public static void main(String[] args) { StringReader reader = new StringReader(); try { int i = 0; // Read in characters one at a time. Character c = readChar(); while (c != null) { reader.append(c); c = readChar(); i++; if (i % 1000 == 0) System.out.println("Read " + i + " characters"); } System.out.print(reader); System.out.print(reader); } catch (IOException e) { System.err.println(e); } } static InputStreamReader in = new InputStreamReader(System.in); // Read one character from System.in, or return null on end-of-file. static Character readChar() throws IOException { int c = in.read(); if (c == -1) return null; else return (char)c; } }