Alex Rivera | Logout

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

Asked 2010-04-29T07:00:14.193
9

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?

Edit
Report

1 Answer

1

this should just work on Android, even without explicitly specifying UTF-8, because the default charset is UTF-8. if you can reproduce this problem, please raise a bug with a reproduceable test case here:

http://code.google.com/p/android/issues/entry

answered 2010-05-09T16:54:40.767

Your Answer