The listing of char[] will probably give you something like:
[ C@1c8825a5
This is just the normal output of calling toString in a char array in Java. It looks like you want to convert it to String , which you can do with the String(char[]) constructor String(char[]) . Here is a sample code:
public class Test { public static void main(String[] args) { char[] chars = "hello".toCharArray(); System.out.println((Object) chars); String text = new String(chars); System.out.println(text); } }
On the other hand, java.io.Reader does not have a read method that returns char[] - it has methods that either return one character at a time or (more useful) take the value char[] to fill in the data and return the amount of data read. This actually shows a sample code. You just need to use the char array and the number of characters read to create a new String . For instance:
char[] buffer = new char[4096]; int charsRead = reader.read(buffer); String text = new String(buffer, 0, charsRead);
However, note that it cannot return all the data in one go. You can read it line by line using BufferedReader , or a loop to get all the information. Guava contains useful code in the CharStreams class, For example:
String allText = CharStreams.toString(reader);
or
List<String> lines = CharStreams.readLines(reader);
source share