zoukankan      html  css  js  c++  java
  • JAVA 字符串编码转换

     /** 
      * 字符串编码转换的实现方法 
      * @param str  待转换编码的字符串 
      * @param newCharset 目标编码 
      * @return 
      * @throws UnsupportedEncodingException 
      */  
     public String changeCharset(String str, String newCharset)  
       throws UnsupportedEncodingException {  
      if (str != null) {  
       //用默认字符编码解码字符串。  
       byte[] bs = str.getBytes();  
       //用新的字符编码生成字符串  
       return new String(bs, newCharset);  
      }  
      return null;  
     }  
     /** 
      * 字符串编码转换的实现方法 
      * @param str  待转换编码的字符串 
      * @param oldCharset 原编码 
      * @param newCharset 目标编码 
      * @return 
      * @throws UnsupportedEncodingException 
      */  
     public String changeCharset(String str, String oldCharset, String newCharset)  
       throws UnsupportedEncodingException {  
      if (str != null) {  
       //用旧的字符编码解码字符串。解码可能会出现异常。  
       byte[] bs = str.getBytes(oldCharset);  
       //用新的字符编码生成字符串  
       return new String(bs, newCharset);  
      }  
      return null;  
     }  
  • 相关阅读:
    JSONP
    函数式编程
    Cookie
    IE userData
    Web Storage
    前端学PHP之会话Session
    数据结构之归并排序
    数据结构之冒泡排序
    数据结构之插入排序
    数据结构之选择排序
  • 原文地址:https://www.cnblogs.com/Cailf/p/9995362.html
Copyright © 2011-2022 走看看