环境:英文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文中的怎么处理。
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文中的怎么处理。
解决方案 »
- 找不到类com.sun.awt.AWTUtilities.
- 为何查询数据库时提示:非法的游标状态?
- 如何获一个包中包含的所有文件
- 高分求救java加密解密xml文件,最好有源程序,谢谢
- 初用eclipse,求教
- 怎么让JFrame的最大化最小化关闭3个按钮在title的左边?
- 初学java,求java基础与案例开发详解 张孝全 pdf电子书
- tree,table新建,删除节点得刷新问题?
- 如何用java实现字符串replace(str1,str2)
- 请问如何在jtable的column中的每个cell中设成不同的类!请大虾们帮忙啦,我只有43分全部奉送啦
- 'class' or 'interface' expected 锘縤mport javax.swing.*;
- JAVA内的最简单的IO操作问题
这些乱码分为2类,楼主心中一定要分清楚:1. 一种情况是:程序的处理过程本身就是错的,因此显示出来乱码。
2. 另一种情况是:程序是对的,由于控制台是英文的无法显示汉字而显示乱码。第二种情况中,程序是对的,也就是说,虽然在控制台显示是乱码,但如果作为服务程序,当客户端是中文环境是,能够正常显示中文。
而第一种情况中,就算是作为服务程序,客户端是中文时仍然会是乱码。因此,光凭着这样试是无法拿出最好的方案来的。推荐楼主从概念入手,掌握其中的原理:
http://www.regexlab.com/zh/encoding.htm
file.encoding:GBK
sun.jnu.encoding:GBK
现在开始测试
??????
??板?ㄥ??濮?娴?璇?
现在开始测试
现在开始测试
??b??l??
??????
file.encoding:UTF-8
sun.jnu.encoding:UTF-8
现在开始测试
??????
??板?ㄥ??濮?娴?璇?
现在开始测试
现在开始测试
??b??l??
??????目前还是在英文环境怎么解决