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;  
     }  
  • 相关阅读:
    bzoj 1503
    bzoj 1193 贪心+bfs
    bzoj 1798 线段树
    Codeforces 804D Expected diameter of a tree
    bzoj 1208
    bzoj 3224
    HDU 5115 区间dp
    hihocoder #1162 矩阵加速dp
    分块入门
    bzoj 1036 树链剖分
  • 原文地址:https://www.cnblogs.com/Cailf/p/9995362.html
Copyright © 2011-2022 走看看