中文问题 你说用getBytes("GBK")吗?试过了,不行 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面的有方法你自己都试试:/** * <p>Title: 字符编码转换</p> * <p>Description: String Conversion 该类实现了各种字符编码之间的转换,包括Unicode、GB2312、BIG5</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: TongJi NRDS</p> * @author fangcheng * @version 1.0 */public class StrCvs{ /** * Unicode字符编码转换为GB2312字符编码 * @param str 输入的字符串编码为Unicode * @return 输出的字符串编码为GB2312 */ public static String UnicodeToGB2312(String str){ try{ if(str == null || str.equals("")) return ""; String newStr = null; newStr=new String(str.getBytes("ISO8859_1"),"gb2312"); return newStr; } catch(Exception e){ return str; } } public static String GB2312ToUnicode(String str){ try{ if(str == null || str.equals("")) return ""; String newStr = null; newStr = new String(str.getBytes("gb2312"),"ISO8859_1"); return newStr; } catch(Exception e){ return str; } } public static String UnicodeToGBK(String str){ try{ if(str == null || str.equals("")) return ""; String newStr = null; newStr=new String(str.getBytes("ISO8859_1"),"GBK"); return newStr; } catch(Exception e){ return str; } } public static String GBKToUnicode(String str){ try{ if(str == null || str.equals("")) return ""; String newStr = null; newStr = new String(str.getBytes("GBK"),"ISO8859_1"); return newStr; } catch(Exception e){ return str; } } public static String DBStrToUnicode(String str){ try{ if(str == null || str.equals("")) return ""; String newStr = null; newStr = new String(str.getBytes(),"ISO8859_1"); return newStr; } catch(Exception e){ return str; } } public static String ByteStreamToUnicode(byte[] byteStream){ try{ if(byteStream == null || byteStream.length == 0) return ""; String newStr = null; newStr = new String(byteStream,"ISO8859_1"); return newStr; } catch(Exception e){ return byteStream.toString(); } }} 将newStr = new String(byteStream,"ISO8859_1");换成newStr = new String(byteStream,"UTF-8");实验一下 常见中文问题的解决方法: 1.JDK的中文问题: 不要使用DataInputStream与DataOutputStream,而要用 BufferedReader与BufferedWriter。2.Visual Age3.0的中文问题: 很简单。在Window-option菜单中给List、Source的选项 设置支持中文的字体就可以了。 3.数据库中文问题: Access + Javaodbc驱动程序不能支持中文(用getByte()也 不行),目前我还没有找到解决方法。 MySQl + Javaodbc驱动程序也有中文问题,目前我还没有找 到解决方法。 MySQl + mm.mysql.jdbc没有任何中文问题,但是建立数据 表,有中文输入的域,最好设成bianry,否则因为MySQL的 varchar、char、text等属性的域在查询时是不分大小写时, 这样中文查询时会出现问题。4.Jsp的中文问题。 setPropotery时的中文问题,使用URLDecoder.decode()进行 转换即可。 救命啊!MyEclipse崩溃啦! 求java Web开发新技术 关于localhost和127.0.0.1的问题,大家都有分儿。 IE发送get而非想要的post请求 Eclipse与oracle连接前要做哪些工作 为什么页面不能动态跳转,但可以静态跳转? 为什么大家多用GB2312 而不是GBK? 谢谢 如何让IE运行(*.exe)可执行程序时,不需下载后再运行,而是直接运行。 多表查询问题! nginx+websocket 收到101响应但立刻断开 关于session,打开新窗口后session就不见了? 请给一个JBuilder的序列号和key,borland上下载不了。
* <p>Title: 字符编码转换</p>
* <p>Description: String Conversion 该类实现了各种字符编码之间的转换,包括Unicode、GB2312、BIG5</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: TongJi NRDS</p>
* @author fangcheng
* @version 1.0
*/public class StrCvs{ /**
* Unicode字符编码转换为GB2312字符编码
* @param str 输入的字符串编码为Unicode
* @return 输出的字符串编码为GB2312
*/
public static String UnicodeToGB2312(String str){
try{
if(str == null || str.equals("")) return "";
String newStr = null;
newStr=new String(str.getBytes("ISO8859_1"),"gb2312");
return newStr;
}
catch(Exception e){
return str;
}
} public static String GB2312ToUnicode(String str){
try{
if(str == null || str.equals("")) return "";
String newStr = null;
newStr = new String(str.getBytes("gb2312"),"ISO8859_1");
return newStr;
}
catch(Exception e){
return str;
}
}
public static String UnicodeToGBK(String str){
try{
if(str == null || str.equals("")) return "";
String newStr = null;
newStr=new String(str.getBytes("ISO8859_1"),"GBK");
return newStr;
}
catch(Exception e){
return str;
}
} public static String GBKToUnicode(String str){
try{
if(str == null || str.equals("")) return "";
String newStr = null;
newStr = new String(str.getBytes("GBK"),"ISO8859_1");
return newStr;
}
catch(Exception e){
return str;
}
} public static String DBStrToUnicode(String str){
try{
if(str == null || str.equals("")) return "";
String newStr = null;
newStr = new String(str.getBytes(),"ISO8859_1");
return newStr;
}
catch(Exception e){
return str;
}
} public static String ByteStreamToUnicode(byte[] byteStream){
try{
if(byteStream == null || byteStream.length == 0) return "";
String newStr = null;
newStr = new String(byteStream,"ISO8859_1");
return newStr;
}
catch(Exception e){
return byteStream.toString();
}
}}
newStr = new String(byteStream,"ISO8859_1");
换成
newStr = new String(byteStream,"UTF-8");
实验一下
不要使用DataInputStream与DataOutputStream,而要用 BufferedReader与BufferedWriter。2.Visual Age3.0的中文问题: 很简单。在Window-option菜单中给List、Source的选项 设置支持中文的字体就可以了。 3.数据库中文问题: Access + Javaodbc驱动程序不能支持中文(用getByte()也 不行),目前我还没有找到解决方法。 MySQl + Javaodbc驱动程序也有中文问题,目前我还没有找 到解决方法。 MySQl + mm.mysql.jdbc没有任何中文问题,但是建立数据 表,有中文输入的域,最好设成bianry,否则因为MySQL的 varchar、char、text等属性的域在查询时是不分大小写时, 这样中文查询时会出现问题。4.Jsp的中文问题。 setPropotery时的中文问题,使用URLDecoder.decode()进行 转换即可。