-
Using BufferedReader
I have this code, purpose is print again what user have typed.
Code:
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
System.out.println(kb.readLine()); //successful;
{
kb.readLine();
System.out.println(kb);
} //compiled, but not successful:It doesn't print what I have typed;
So, who know what wrong it is, help me please.
thanks :)
-
Re: Using BufferedReader
The BufferedReader#readLine() method returns what is read in as a String. In your second attempt to use it you're reading in from the BufferedReader but not saving the String that is returned but instead just discarding it, and then trying to print out the BufferedReader object itself which you're finding doesn't work. It's as if you wrote a letter to someone and then threw out the letter but mailed them the pen you used. Instead you want to create a String variable, assign to it the String that is returned by the readLine() method and then print it out.