java的中文亂碼轉換

weixin_34321977發表於2012-03-25

java的中文亂碼轉換 - netky的專欄 - 部落格頻道 - CSDN.NET

java的中文亂碼轉換


分類:
java技術


1749人閱讀
評論(0)
收藏
舉報

 

/*
編碼轉換,確保寫資料庫的時候不會出現亂碼
*/

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;
 }
}

相關文章