wsfeiyuan 发表于 2013-2-5 10:12:57

java编码转换

/*
编码转换,确保写数据库的时候不会出现乱码
*/
public class CodingConvert
{  
 public CodingConvert()
 {
  //
 }
 public String toGb(String uniStr){
     String gbStr = "";
     if(uniStr == null){
   uniStr = "";
     }
     try{
   byte[] tempByte = uniStr.getBytes("ISO8859_1");
   gbStr = new String(tempByte,"GB2312");
     }
  catch(Exception ex){
    }
     return gbStr;
 }
  
 public String toUni(String gbStr){
     String uniStr = "";
     if(gbStr == null){
   gbStr = "";
     }
     try{
   byte[] tempByte = gbStr.getBytes("GB2312");
   uniStr = new String(tempByte,"ISO8859_1");
     }catch(Exception ex){
    }
    return uniStr;
 }
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/netky/archive/2005/06/03/387310.aspx
页: [1]
查看完整版本: java编码转换