i want prompt user begin entering characters , want them able enter characters long want until hit control+d exit.
for example, can type string of numbers like: 1234567 , decide hit control+d line entered displayed (so without having hit return)
i thinking i'll need buffered reader or something. suggestions?
http://download.oracle.com/javase/6/docs/api/java/io/bufferedinputstream.html#read%28%29
public class inputtest { public static void main(string[] args) throws ioexception { bufferedreader in = new bufferedreader(new inputstreamreader(system.in)); stringbuilder out = new stringbuilder(); while (true) { try { int c = in.read(); if (c != 4) // ascii 4 04 eot (end of transmission) ctrl d, may wrong here out.append (c); else break; } catch (ioexception e) { system.err.println ("error reading input"); } } system.out.println(out.tostring()); } }
Comments
Post a Comment