I just found out that Android can correctly read in a file which is encoded using Windows ANSI (or the so-called multi-byte encoding) and convert it to Java Unicode strings. But it fails when reading a Unicode file. It seems that Android is reading it in a byte-by-byte fashion. A Unicode string "ABC" in the file would be read in to a Java String of length 6, and the characters are 0x41, 0x00, 0x42, 0x00, 0x43, 0x00.
BufferedReader in = new BufferedReader(new FileReader(pathname)); String str = in.readLine(); Please, is there a way to read Windows Unicode files correctly on Android? Thank you.
[Edited]
Experiements: I saved two Chinese characters "難哪" in two Windows text files:
ANSI.txt -- C3 F8 AD FE UNICODE.txt -- FF FE E3 96 EA 54 Then I put these files to Emulator's SD card, and I used the following program to read them in: (Notice that the locale of the Emulator has already been set to zh_TW).
BufferedReader in = new BufferedReader(new FileReader("/sdcard/ANSI.txt")); String szLine = in.readLine(); int n = szLine.length(), j, i; in.close(); for (i = 0; i < n; i++) j = szLine.charAt(i); Here is what I saw on the Emulator:
ANSI.txt -- FFFD FFFD FFFD UNICODE.txt -- FFFD FFFD FFFD FFFD 0084 Apparantly Android (or Java) is unable to properly decode the Chinese characters. So, how do I do this? Thank you in advance.