zoukankan      html  css  js  c++  java
  • java 编码转换

      

    package test;
    
    import java.util.Map;
    
    public class Test3
    {
        public static Map<String,Object> map;
        public static void main(String[] args) throws Exception
        {
            String str = "严";
    //        "GBK","UTF-8"
            byte[] bytes = str.getBytes("UTF-8");
            printHexString(bytes);
            System.out.println();
            String str2 = new String(bytes,"UTF-8");
            System.out.println(str2);
            
        }
        
        //将指定byte数组以16进制的形式打印到控制台   
        public static void printHexString( byte[] b) {     
           for (int i = 0; i < b.length; i++) {    
             String hex = Integer.toHexString(b[i] & 0xFF);    
             if (hex.length() == 1) {    
               hex = '0' + hex;    
             }    
             System.out.print(hex.toUpperCase() );    
           }    
          
        }  
    }

     相关函数

    byte[] bytes = str.getBytes("UTF-8");

     以指定的字符集对字符串进行编码,结果存放在byte数组中

    String str2 = new String(bytes,"UTF-8");

     以指定的字符集对给定的byte数组进行解码

    "严"的UTF编码为:E4B8A5,GBK编码为:D1CF

  • 相关阅读:
    PRCT-1302 the OCR has an invalid ip address
    函数listen
    函数bind
    函数socket
    lamp。查看版本
    yii 日期插件
    UCenter 的目录结构
    API接口
    返回标签数据示例 (PHP)
    应用接口函数
  • 原文地址:https://www.cnblogs.com/hoonick/p/9933540.html
Copyright © 2011-2022 走看看