# java BufferedReader.read() convert to char



## sbussy89

Ok, so Java's BufferedReader read method returns an int, but I want to read one char at a time and store them as chars. How can I convert this returned int to a char?


----------



## shuuhen

Unless I'm thinking of a different language, you should be able to convert the int directly to a char. At least in C, int and char are both integer types. They just hold different numbers of bytes. Java should allow you to convert an int to a char as long as you use a cast. Something like

// assuming input is a BufferedReader
char letter = (char)input.read();

Although it is a narrowing conversion, so you may need to add some code to check cases where the value doesn't fit in a char.


Or you could use BufferedReader.readLine() and access each char from the String (using String.charAt() - note this is an instance method).


----------

