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

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-10-20
  • 2022-02-15
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2021-10-16
  • 2022-02-08
  • 2022-12-23
  • 2021-12-28
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案