Saturday, September 27, 2008

big-endian UTF16 or little-endian UTF16?

I was working on generating configuration file for mobile device on PC today.
From the example, I can tell that it is using two bytes Unicode.
Thus I am using 'UTF-16' encoding for InputStreamReader and OutputStreamWriter.

However, it seems that the server running on mobile device doesn't like my configuration file.
By looking into the example and generated files, I notice that it was using little-endian UTF-16.
So I changed to use the following statement to write content in little-endian UTF16 encoding.

OutputStreamWriter out = new OutputStreamWriter(
new FileOutputStream(iniFile), "UTF-16LE");


Here are Unicode table for reference:























EncodingFile initial signatureJava encoding name
UTF 8FF BB BFUTF8
UTF 16 Big-EndianFE FFUTF16-BE
UTF 16 Little-EndianFF FE UTF16-LE