简体   繁体   English

2 字节 UTF-8 Java 的无效字节 2,序列错误取决于 Windows/IntelliJ

[英]Invalid byte 2 of 2-byte UTF-8 Java, sequence error depending on Windows/IntelliJ

So the same code is running on both of the devices, both PCs are running Windows 10, but the variable is represented different in IntelliJ debugger and one can decode string, and other can't.所以相同的代码在两台设备上运行,两台 PC 都运行 Windows 10,但变量在 IntelliJ 调试器中表示不同,一个可以解码字符串,另一个不能。 Both are accessing same endpoint.两者都访问相同的端点。 This is code snippet that's throwing error and where code breaks.这是抛出错误和代码中断的代码片段。 Both code are running on the same JRE and getting variable value from same endpoint.两个代码都在同一个 JRE 上运行,并从同一个端点获取变量值。

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);

As I am generating XML file that's UTF-8 encoded, it throws error for that variable.当我生成 UTF-8 编码的 XML 文件时,它会为该变量引发错误。

Variable that's not throwing error on PC1 shown in debugger未在调试器中显示的 PC1 上引发错误的变量

调试器 var 不抛出错误

Variable that's throwing error on PC2在 PC2 上抛出错误的变量

误差变量

I tried reinstalling all JRE, IntelliJ, etc etc, still no help...我尝试重新安装所有 JRE、IntelliJ 等,仍然没有帮助...

Are you sure the file is UTF-8 encoded?您确定该文件是 UTF-8 编码的吗? In my case I realized it was windows-1250 encoding used.就我而言,我意识到它使用的是 windows-1250 编码。 So I had to specify an encoding:所以我必须指定一个编码:

InputStream is = ...
InputSource src = new InputSource(new InputStreamReader(is, Charset.forName("cp1250")));
Document xmlDocument = builder.parse(src);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows中使用Java读取UTF-8格式的xml -file会给出“ IOException:2字节UTF-8序列的无效字节2。” -error - Reading xml -file in UTF-8 format in Windows with Java gives “IOException: Invalid byte 2 of 2-byte UTF-8 sequence.” -error 2 字节 UTF-8 序列的无效字节 2 - invalid byte 2 of 2-byte UTF-8 sequence MalformedByteSequenceException:2字节UTF-8序列的无效字节2 - MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence 2字节UTF-8序列的无效字节2:如何查找字符 - Invalid byte 2 of 2-byte UTF-8 sequence : How to find the character Android studio 2字节UTF-8序列的无效字节2 - Android studio Invalid byte 2 of 2-byte UTF-8 sequence JAXB和UTF-8解组异常“ 2字节UTF-8序列的无效字节2” - JAXB & UTF-8 Unmarshal exception “Invalid byte 2 of 2-byte UTF-8 sequence” 从URL解析RSS给我“ 2字节UTF-8序列的无效字节2” - Parse RSS from URLs gives me “Invalid byte 2 of 2-byte UTF-8 sequence” Selenium Web驱动程序:MalformedByteSequenceException 2字节UTF-8序列的无效字节2 - Selenium Web Driver : MalformedByteSequenceException Invalid byte 2 of 2-byte UTF-8 sequence 嵌套的异常是org.xml.sax.SAXParseException:2字节UTF-8序列的无效字节2 - nested exception is org.xml.sax.SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence 2字节UTF-8序列的无效字节2:XML保存为字符串变量 - Invalid byte 2 of 2-byte UTF-8 sequence: XML saved as String varible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM