关于英文系统开发环境中java的中文处理
sbhjj 2007-05-15 02:48:36 环境:英文XP SP2,Eclipse 3.2,JDK 1.5
使用测试代码:
String encoding = System.getProperty("file.encoding");
System.out.println("file.encoding:" + encoding);
System.out.println("sun.jnu.encoding:" + System.getProperty("sun.jnu.encoding"));
String testString = "现在开始测试";
System.out.println(testString);
System.out.println(new String(testString.getBytes("ISO-8859-1"),"gb2312"));
System.out.println(new String(testString.getBytes("UTF8"), "gb2312"));
System.out.println(new String(testString.getBytes("GB2312"),"gb2312"));
System.out.println(new String(testString.getBytes("GBK"), "gb2312"));
System.out.println(new String(testString.getBytes("BIG5"), "gb2312"));
System.out.println(new String(testString.getBytes("Cp1252"),"gb2312"));
System.clearProperty("file.encoding");
System.setProperty("file.encoding", "UTF-8");
System.setProperty("sun.jnu.encoding", "UTF-8");
System.out.println("file.encoding:" + System.getProperty("file.encoding"));
System.out.println("sun.jnu.encoding:" + System.getProperty("sun.jnu.encoding"));
System.out.println(testString);
// 这一段出现了乱码,那么不妨用穷举法猜测一下它的实际编码格式。
System.out.println(new String(testString.getBytes("ISO-8859-1"),"gb2312"));
System.out.println(new String(testString.getBytes("UTF8"), "gb2312"));
System.out.println(new String(testString.getBytes("GB2312"),"gb2312"));
System.out.println(new String(testString.getBytes("GBK"), "gb2312"));
System.out.println(new String(testString.getBytes("BIG5"), "gb2312"));
System.out.println(new String(testString.getBytes("Cp1252"),"gb2312"));
Console log为:
file.encoding:Cp1252
sun.jnu.encoding:GBK
??????
??????
?????????????
??????
??????
??b??l??
??????
file.encoding:UTF-8
sun.jnu.encoding:UTF-8
??????
??????
?????????????
??????
??????
??b??l??
??????
请大家来支支招,这类的Console文中的怎么处理。