Skip to content Skip to sidebar Skip to footer

Android Utf-8 Encoding Not Working?

I am working with a CSV file right now. In my program i am using an OutputStreamWriter to write data the csv file. OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut, Ch

Solution 1:

Your file is actually UTF-8 not CP-1252. Your text editor/viewer detected it as CP-1251 (since no multi-byte characters). You can help your editor by adding byte order mark (BOM) in the beginning of the file. I.e.

staticfinalbyte[] UTF8_BOM = {0xEF,0xBB,0xBF};
...
fOut.write(UTF8_BOM);
OutputStreamWritermyOutWriter=newOutputStreamWriter(fOut, Charset.forName("UTF-8").newEncoder());

Solution 2:

Did you try opening it in EXCEL? For EXCEL to recognize the file as UTF-8 it needs to have BOM (https://en.wikipedia.org/wiki/Byte_order_mark)

Post a Comment for "Android Utf-8 Encoding Not Working?"