Java 字节数组通过 UTF-8 编码成字符串后,无法恢复到原始字节数组
資深大佬 : yanshenxian 5
代码如下
byte[] bytes = new byte[] {39, 10, -111, -111, 54, 68, -2, 89, 68, 20, -92, 73, -83, -11, -5, -54, -122, -127, 97, 64}; String stringValue = new String(bytes, StandardCharsets.UTF_8); byte[] newBytes1 = stringValue.getBytes(StandardCharsets.UTF_8); byte[] newBytes2 = stringValue.getBytes(StandardCharsets.ISO_8859_1); // 输出 false System.out.println(Arrays.equals(bytes, newBytes1)); // 输出 false System.out.println(Arrays.equals(bytes, newBytes2));
我要怎么将一个 UTF-8 编码的字符串恢复成原始字节数组呢
大佬有話說 (1)