BufferedReader is a decorator that decorates another reader. InputStream is not a reader. First you need an InputStreamReader.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
In response to your comment here's javadoc for readline:
Readline
public String readLine()
throws IOException
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
To deal with this, you need to either put the method call in a try / catch block or declare that it can be thrown.
An example of using the try / catch block:
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
try{
String filename = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error");
System.exit(1);
}
An example of declaring that an exception can be thrown:
void someMethod() throws IOException {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String filename = br.readLine();
}
source
share