Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read unicode text files with java

Real simple question really. I need to read a Unicode text file in a Java program.

I am used to using plain ASCII text with a BufferedReader FileReader combo which is obviously not working :(

I know that I can read a String in the 'traditional' way using a Buffered Reader and then convert it using something like:

temp = new String(temp.getBytes(), "UTF-16");

But is there a way to wrap the Reader in a 'Converter'?

EDIT: the file starts with FF FE

like image 919
Ron Tuffin Avatar asked Jun 11 '09 08:06

Ron Tuffin


1 Answers

you wouldn't wrap the Reader, instead you would wrap the stream using an InputStreamReader. You could then wrap that with your BufferedReader that you currently use

BufferedReader in = new BufferedReader(new InputStreamReader(stream, encoding));
like image 56
objects Avatar answered Nov 11 '22 04:11

objects