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;  
     }  
  • 相关阅读:
    php 数组
    条件语句if else ,switch ,while ,do.while
    if..else 判断中的 Boolean()转换
    wampserver 集成环境
    sublime text 安装及使用
    vue tab切换
    SVG 基础
    gitosis管理员的密钥丢失解决办法
    源码安装MySQL
    Xshell远程登录
  • 原文地址:https://www.cnblogs.com/Cailf/p/9995362.html
Copyright © 2011-2022 走看看