0

Java 以 UCS-2 格式存储字符。

    byte[] bytes = {0x00, 0x48, 0x00, 0x69, 0x00, 0x2c,
                    0x60, (byte)0xA8, 0x59, 0x7D, 0x00, 0x21};
    // Print UCS-2 in hex codes
    System.out.printf("%10s", "UCS-2");
    for(int i=0; i<bytes.length; i++) {
        System.out.printf("%02x", bytes[i]);
    }

1)在下面的代码中,

    Charset charset = Charset.forName("UTF-8");
    // Encode from UCS-2 to UTF-8
    // Create a ByteBuffer by wrapping a byte array
    ByteBuffer bb = ByteBuffer.wrap(bytes);

用于存储的字节顺序bytesbb什么wrap()?BigEndian 还是 LittleEndian?

2)在下面的代码中,

    // Create a CharBuffer from a view of this ByteBuffer
    CharBuffer cb = bb.asCharBuffer();
    ByteBuffer bbOut = charset.encode(cb);

用于将字节存储bb为字符cb的编码格式是什么asCharBuffer()

4

0 回答 0