string byte[] 互转

 import java.io.UnsupportedEncodingException;

    public class HelloWorld {
    
    
        public static void main(String[] args) {
    
    


            String str = "{[type=123456,data=123123]}";
            System.out.println(" " + str);

            byte[] bytes2 = str.getBytes();

            for (int i = 0; i < bytes2.length; i++) {
    
    

                System.out.print(Integer.toHexString(bytes2[i] & 0xFF) + " ");

            }
            System.out.println(" ");

            try {
    
    
                String str1 = new String(bytes2, "UTF-8");
                System.out.println("UTF-8:" + str1);

                String str2 = new String(bytes2, "GB2312");

                System.out.println("GB2312:" + str2);

            } catch (UnsupportedEncodingException e) {
    
    
                e.printStackTrace();
                System.out.println(" " + e.getMessage());
            }


            //

            System.out.println("Hello World!");
        }
    }

猜你喜欢

转载自blog.csdn.net/ZQ200720/article/details/128843710
今日推荐