这是 XML 内的前三个字符。

huangapple go评论73阅读模式
英文:

What this the first three characters inside xml

问题

以下是您提供的内容的翻译部分:

为什么我使用 Java 将文件内容读取为字节数组后得到如下输出?

File f = new File("exampleData.xml");
byte[] data = getBytesFromFile("data.xml");
for (byte zeichen : data) {
    char zzeichenCharacter = (char)zeichen;
    System.out.println(zzeichenCharacter + "  : " + String.valueOf(zeichen));
}

输出:

￯  : -17
ᄏ  : -69
﾿  : -65
<  : 60
?  : 63

而当我将 exampleData.xml 文件的内容复制到一个名为 exampleDataCopy.xml 的第二个文件中,然后使用相同的代码,我得到了不同的输出:

<  : 60
?  : 63
x  : 120
m  : 109
l  : 108
英文:

Why i got following output by reading the content of file as byte array with java?

File f = new File( "exampleData.xml" );
byte[] data = getBytesFromFile("data.xml");
for (byte zeichen : data) {
	char zzeichenCharacter = (char)zeichen;
	System.out.println(zzeichenCharacter + "  : " + String.valueOf(zeichen));
}

Output:

￯  : -17
ᄏ  : -69
﾿  : -65
<  : 60
?  : 63

And when I copy the content from the file exampleData.xml to a second file with name exampleDataCopy.xml and using the same code above I got a different output:

<  : 60
?  : 63
x  : 120
m  : 109
l  : 108

答案1

得分: 1

第一个字节是字节顺序标记的UTF-8编码。

十六进制表示为EF BB BF

你应该以UTF-8格式读取文件,而不是逐字节处理。

英文:

The first three bytes are the UTF-8 encoding of the Byte order mark.

The hexadecimal representation is EF BB BF.

You should read your file as UTF-8 instead of processing it byte by byte.

huangapple
  • 本文由 发表于 2020年9月9日 16:52:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63808116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定