Reading Text from Standard Input

try {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = "";
    while (str != null) {
        System.out.print("> prompt ");
        str = in.readLine();
        process(str);
    }
} catch (IOException e) {
}

Comments

8 Jan 2010 - 3:50am by Anonymous (not verified)

applet program

9 Feb 2011 - 12:38am by Anonymous (not verified)

this could be improved with

while ((str = bin.readLine()) != null) {
process(str);
}

since there will be no call of process() with null value.

24 May 2011 - 4:39am by zggtf211 (not verified)

I would like to know the need for the try/catch. Is there a way to crash a program using standard input?

12 Jul 2011 - 10:22pm by prince (not verified)

maganda sya

2 Dec 2011 - 1:14am by beats by dre solo (not verified)

good

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.