软件是对质量的不懈追求

汉字与utf8编码相互转换


import java.io.UnsupportedEncodingException;


public class UTF {

    public static void main(String[] args) {
        String s 
= "非常好";
        
try {
            
byte[] b = s.getBytes("UTF-8");
            
for(int i=0; i< b.length; i++){
                System.out.println(Integer.toHexString(b[i]).substring(
6));
                
            }
            System.out.println(
new String(b, "UTF-8"));

        } 
catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } 
        

    }

}

输出:
e9
9d
9e
e5
b8
b8
e5
a5
bd
非常好

posted on 2010-02-26 13:39 BlakeSu 阅读(190) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: