How to read and write UTF-8 to disk on the Android?

Posted by Rob Kent on Stack Overflow See other posts from Stack Overflow or by Rob Kent
Published on 2010-04-29T07:00:14Z Indexed on 2010/04/29 7:37 UTC
Read the original article Hit count: 218

Filed under:
|
|
|

I cannot read and write extended characters (French accented characters, for example) to a text file using the standard InputStreamReader methods shown in the Android API examples. When I read back the file using:

InputStreamReader tmp = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(tmp);
String str;
while ((str = reader.readLine()) != null) {
...

the string read is truncated at the extended characters instead of at the end-of-line. The second half of the string then comes on the next line. I'm assuming that I need to persist my data as UTF-8 but I cannot find any examples of that, and I'm new to Java.

Can anyone provide me with an example or a link to relevant documentation?

© Stack Overflow or respective owner

Related posts about java

Related posts about character-encoding