I try to set the encoding of my editor to UTF-16. (Java String store the data in UTF-16 internally, right?)
alt text http://sites.google.com/site/yanchengcheok/Home/helloworld.png
And I type the following code
package helloworld;
/**
*
* @author yan-cheng.cheok
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("我爱你");
System.out.println("\u6587\u4EF6\u79CD\u7C7B");
}
}
However, the output is not what I expected :
alt text http://sites.google.com/site/yanchengcheok/Home/helloworld1.png
我爱你�
文件种类�
I try to change the editor encoding format to UTF-8, it works this time!
我爱你
文件种类
May I know why I need to change the editor encoding format to UTF-8 but not UTF-16? Isn’t Java String store the data in UTF-16 internally?
Looks like a limitation of the underlaying platform ( Windows in this case ) which doesn’t fully support UTF-16
Try investigating around this:
http://wiki.netbeans.org/TextEncodingFOW
https://bugs.java.com/bugdatabase/view_bug?bug_id=4163515
They’re not definitive answers but may lead you.