public class BytesTest{
public static void main(String[] args) throws Exception{
String str="在哪里where";
System.out.println(str);
String strUC=new String(str.getBytes(),"Unicode");
System.out.println(strUC);
}
}在学习java的时候说java默认的编码方式是Unicode,那这样输出为什么是乱码,
而把str.getBytes()括号里加上"Unicode",指定编码方式,这样又可以正常输出呢?
public static void main(String[] args) throws Exception{
String str="在哪里where";
System.out.println(str);
String strUC=new String(str.getBytes(),"Unicode");
System.out.println(strUC);
}
}在学习java的时候说java默认的编码方式是Unicode,那这样输出为什么是乱码,
而把str.getBytes()括号里加上"Unicode",指定编码方式,这样又可以正常输出呢?
例如:我的eclipse里面编码是MS932String str="在那里where";
System.out.println(str);
String strUC=new String(str.getBytes(),"MS932");
System.out.println(strUC);结果:在那里where
在那里where
public static void main(String[] args) throws Exception{
String str="在哪里where";
System.out.println(str);
String strUC=new String(str.getBytes());
System.out.println("123");
System.out.println(strUC);
}
可以正常显示!