I'm trying to convert my StringReader
back to a regular String
, as shown:
String string = reader.toString();
But when I try to read this string out, like this:
System.out.println("string: "+string);
All I get is a pointer value, like this:
java.io.StringReader@2c552c55
Am I doing something wrong in reading the string back?
Another native (Java 8+) solution could be to pass the
StringReader
object to aBufferedReader
and stream trough the lines:Calling toString() method will give the object of StringReader class. If yo want it's content then you need to call the read method on StringReader like this:
For tutorials you can use this link.
If you prefer not to use external libraries:
The reason for the
hasNext()
check is thatnext()
explodes with aNoSuchElementException
if the reader wraps a blank (zero-length) string.