// // class to read lines from standard input without using the // BufferedReader class, which apparently does not work well // under Windows. // // LineInput.readLine() returns a string containing a line from // standard input (up to line feed / carriage return). // it returns null on end of file. compare with CIS3020 Input // class, which throws an exception on end of file. // // see main method for example of use. import java.io.*; public class LineInput { // make a reader for standard input (System.in). static Reader br = new InputStreamReader(System.in) ; static String readLine() { try { StringBuffer sb = new StringBuffer() ; int ich = br.read() ; char ch = (char) ich ; if (ich == -1) { return null ; } else { // at least one character has been read while (ch != '\n' && ch != '\r' && ich != -1) { sb.append(ch) ; ich = br.read() ; ch = (char) ich ; } return sb.toString() ; } } // end of 'try' catch (IOException e) { // don't really expect this to happen, so // just end the program throw new RuntimeException("I/O error!") ; } } // main method (demonstrates use) public static void main(String[] args) { String s ; System.out.println("Enter lines to echo:") ; do { s = LineInput.readLine() ; if (s != null) System.out.println("Read: " + s) ; } while (s != null) ; System.out.println("That's all, folks!") ; } }