代码如下
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
yanshenxian OP 自答: 在 Stack Overflow 上找到答案了
is-there-a-way-to-recover-a-byte-array-that-represents-a-string-that-is-saved-a |