《java字符编码探究相关小函数.docx》由会员分享,可在线阅读,更多相关《java字符编码探究相关小函数.docx(4页珍藏版)》请在金锄头文库上搜索。
1、 java字符编码探究相关小函数* UTF-16 charset 使用 16 位量,因此对字节挨次敏感。 流的字节挨次可以由 Unicode 字符 uFEFF* 所表示的初始字节挨次标记 来指示。* UTF-16BE 16 位 UCS 转换格式,Big Endian(最低地址存放高位字节)字节挨次* UTF-16LE 16 位 UCS* 转换格式,Little-endian(地址存放低位字节)字节挨次* java中 假如没有feff的标志,则默认为 feff* throws UnsupportedEncodingException*/void unicodeShow() throws Unsu
2、pportedEncodingException String shz;byte hz;hz = new byte4;hz0 = (byte) 0xfe;hz1 = (byte) 0xff;hz2 = 0x55;hz3 = 0x4a;shz = new String(hz, “utf-16“);System.out.println(shz);hz = new byte2;hz0 = 0x55;hz1 = 0x4a;shz = new String(hz, “utf-16“);System.out.println(shz);hz = new byte2;hz0 = 0x55;hz1 = 0x4a
3、;shz = new String(hz, “utf-16be“);System.out.println(shz);hz = new byte4;hz0 = (byte) 0xff;hz1 = (byte) 0xfe;hz2 = 0x4a;hz3 = 0x55;shz = new String(hz, “utf-16“);System.out.println(shz);hz = new byte2;hz0 = 0x4a;hz1 = 0x55;shz = new String(hz, “utf-16le“);System.out.println(shz);System.out.println(“
4、啊 UNICODE:U+554A“);System.out.print(Integer.toHexString(“啊“.charAt(0) 8System.out.print(“ “);System.out.print(Integer.toHexString(“啊“.charAt(0)System.out.println();for (byte i : “啊“.getBytes(“utf-16“)System.out.print(Integer.toHexString(iSystem.out.println();for (byte i : “啊“.getBytes(“utf-16be“)System.out.print(Integer.toHexString(iSystem.out.println();for (byte i : “啊“.getBytes(“utf-16le“)System.out.print(Integer.toHexString(iSystem.out.println();