汉字与utf8编码相互转换


<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> 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
非常好

你可能感兴趣的:(utf8)