[英]dagger output java (char)134 doesnt work cp1252
Normally my program should put out all CP1252 code as chars: 通常,我的程序应将所有CP1252代码以char形式输出:
System.out.println("actual file.encoding: "+System.getProperty("file.encoding")); // CP1252
for (int i = 0; i < 500; i++) {
System.out.println("Nr.: "+i+ " Symbol: "+(char)i");
}
But output is: (snippet of the whole output!) 但是输出是:(整个输出的片段!)
Nr.: 124 Symbol: |
Nr.: 125 Symbol: }
Nr.: 126 Symbol: ~
Nr.: 127 Symbol:
Nr.: 128 Symbol: ?
Nr.: 129 Symbol: ?
Nr.: 130 Symbol: ?
Nr.: 131 Symbol: ?
Nr.: 132 Symbol: ?
Nr.: 133 Symbol: ?
Nr.: 134 Symbol: ?
Nr.: 135 Symbol: ?
But in https://en.wikipedia.org/wiki/Windows-1252 it is written that 134 is: † 但是在https://en.wikipedia.org/wiki/Windows-1252中 ,写成134是:†
Why doesn't it show † ? 为什么不显示†?
The byte value 134 (or 0x86) in CP1252 is indeed dagger, but char
in Java is always UTF-16 (Unicode) and in UTF-16 U+0080 - U+00FF (integer codepoints 128 - 159) are non-graphic characters while U+2020 is the character corresponding to CP1252 byte 0x86. CP1252中的字节值134(或0x86)确实是匕首,但Java中的
char
始终为UTF-16(Unicode),而在UTF-16中, char
始终为非图形字符U + 0080-U + 00FF(整数代码点128-159)而U + 2020是与CP1252字节0x86对应的字符。
Use System.out.write(/*int 0-255 only*/i)
to output an already-encoded byte . 使用
System.out.write(/*int 0-255 only*/i)
输出已编码的byte 。 Or less convenient in this case but preferable in others, put the bytes in an array byte[]
and use System.out.write(byte[])
. 或者在这种情况下不太方便,但在其他情况下更可取,请将字节放入数组
byte[]
并使用System.out.write(byte[])
。
ah now it works... Someone knows which charsets are involed here ? 啊,现在可以用了...有人知道这里涉及哪些字符集吗? i will find out later but now it is to confusing.
我稍后会发现,但现在却令人困惑。 Thank you: It works with the Unicode U+2020 (hex) which correspond to 8224 :
谢谢:它适用于Unicode U + 2020(十六进制),它对应于8224:
fW.write("Omg it writes † : ");
fW.write(13);
fW.write(10);
fW.write(0x2020);
fW.write(8224);
fW.write(13);
fW.write(10);
Output: 输出:
Begin:
Omg it writes † :
††
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.