简体   繁体   中英

dagger output java (char)134 doesnt work cp1252

Normally my program should put out all CP1252 code as chars:

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: †

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.

Use System.out.write(/*int 0-255 only*/i) to output an already-encoded byte . Or less convenient in this case but preferable in others, put the bytes in an array byte[] and use 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 :

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 † : 
††

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM