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

    xiaoxiao2021-03-25  95

    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()); } } }
    转载请注明原文地址: https://ju.6miu.com/read-23740.html

    最新回复(0)