UTF-8,GBK,ISO8859-1

UTF-8,GBK,ISO8859-1

package com.page2;

public class demobytes {
    public static void main(String[] args) {
        String str="陈";
        try {
            byte[] byte1 = str.getBytes("GBK");
            byte[] byte2 = str.getBytes("UTF-8");
            byte[] byte3 = str.getBytes("ISO8859-1");
            System.out.println("GBK");
            for (byte i : byte1)
                System.out.println(i);
            System.out.println("UTF-8");
            for (byte i : byte2)
                System.out.println(i);
            System.out.println("ISO8859-1");
            for (byte i : byte3)
                System.out.println(i);
            String str1 = new String(byte1, "GBK");// 将byte1转化为utf-8
            System.out.println("GBK还原"+str1);
            String str2= new String(byte2, "UTF-8");// 将byte1转化为utf-8
            System.out.println("utf8还原"+str2);
            String str3 = new String(byte3, "ISO8859-1");// 将byte1转化为utf-8
            System.out.println("iso8859-1还原"+str3);

            //化为iso8859-1,使用 之后在化为汉字 用utf-8做桥梁
            byte[] utf8=str.getBytes("UTF-8");
            String iso8859_1=new String(utf8,"ISO8859-1");
            System.out.println("打印iso");
            byte[] iso=iso8859_1.getBytes("ISO8859-1");
            for(byte i:iso)
            {
                System.out.println(i);
            }
            System.out.println("转化为了Iso"+iso8859_1);
            String str_han=new String(iso8859_1.getBytes("ISO8859-1"),"UTF-8");
            System.out.println("转化为汉字"+str_han);

        }
        catch (Exception e){
            System.err.println(e.getMessage());
        }


    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值