String a1 = "Hello world"; byte[] bytes = a1.getBytes(); for (int i =0; i < bytes.length; i++) { System.out.print(bytes[i]); System.out.print("\t"); String s = Integer.toHexString(bytes[i] & 0xFF); System.out.print(s); System.out.print("\t"); byte[] bytes1 = new byte[1]; bytes1[0] = bytes[i]; String s1 = new String(bytes1, Charset.defaultCharset()); System.out.println(s1); }
输入后果
72 48 H101 65 e108 6c l108 6c l111 6f o32 20 119 77 w111 6f o114 72 r108 6c l100 64 d