gpt4 book ai didi

unicode - Java 8 处理与 Java 7 不同的无效 UTF-8 编码....?

转载 作者:行者123 更新时间:2023-12-01 13:50:04 26 4
gpt4 key购买 nike

log.info(new String(new byte[]{-7, 'a'}, "UTF-8").length());

Oracle Java 1.8.0_60 导致打印输出为“2”,1.7.0_79 为“1”。

?

最佳答案

您传递的是无效的 UTF-8 序列。来自docs

The behavior of this constructor when the given bytes are not valid in the given charset is unspecified.

因此在正确的实现中,返回的字符串也可能是 "Hello world!"

关于unicode - Java 8 处理与 Java 7 不同的无效 UTF-8 编码....?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com