4月4日,Decode,每日20行。

来源:互联网 发布:windows连不上无线网 编辑:程序博客网 时间:2024/05/29 04:27
import java.io.*;public class Decode {    public static void printByteArray(String msg, byte[] t){        System.out.println(msg + "****************");        for(int i = 0; i < t.length; i++){            System.out.println(Integer.toHexString(t[i]));        }    }    public static void printCharArray(String msg, char[] c){        System.out.println(msg + "****************");        for(int i = 0; i < c.length; i++){            System.out.println(Integer.toHexString(c[i]));        }    }    public static void main(String[] args) {        byte[] b = new byte[6];        int t = 0, pos = 0;        String s;        try{            while(t != '\n'){                t = System.in.read();    //输入内容按字节读入存放                b[pos] = (byte)t;                pos++;            }            printByteArray("本地码:", b);            s = new String(b, "GBK");    //按照 GBK 方式进行解码            System.out.println(s);            printCharArray("unicode码:", s.toCharArray());        }        catch(Exception e){            System.out.println(e.getMessage());        }    }}
0 0
原创粉丝点击