Java 描绘超出字符范围

Java 描绘超出字符范围,java,Java,当我运行以下语句时 System.out.println("Character is "+(char)65536); //equivalent to 0x10000 我得到的输出是 Character is 如何描述它?该类提供以下方法 Character.highSurrogate(codePoint); Character.lowSurrogate(codePoint); 对于检索代理项,给定一个代码点 一旦有了这些,您就可以将它们写入字节缓冲区,并获得相应的字节[],并使用

当我运行以下语句时

    System.out.println("Character is "+(char)65536); //equivalent to 0x10000
我得到的输出是

Character is 
如何描述它?

该类提供以下方法

Character.highSurrogate(codePoint);
Character.lowSurrogate(codePoint);
对于检索代理项,给定一个代码点

一旦有了这些,您就可以将它们写入
字节缓冲区
,并获得相应的
字节[]
,并使用它创建一个新的
字符串
,使用UTF-16编码

//  byte[] bytes = new byte[] { (byte) 0xD8, 0x34, (byte) 0xDD, 0x1E };
String text = "The method 
Character.toChars(int)
will give you the UTF-16 series of code units corresponding to that code point.

So, for your example:

System.out.println("Character is " + new String(Character.toChars(65536))); //equivalent to U+10000
//字节[]字节=新字节[]{(字节)0xD8,0x34,(字节)0xDD,0x1E};
String text=“该方法将为您提供与该代码点对应的UTF-16系列代码单元

以你为例:


将打印一个U+10000(“线性B音节B008 a”),假设您有该字体。

Java设计用于保存Unicode文本,因此所有语言的所有脚本(如西里尔文、阿拉伯文、希腊文)都可以合并

Unicode符号称为代码点,是需要3个字节的数字。U+10000将是您提到的代码点。它是线性B音节B008 A

在java中,代码点存储在int中。String保存一个char数组,其中char是一个2字节的UTF-16BE编码值。当Unicode进入3字节范围时,有时需要2个char来表示一个代码点。UTF-16编码确保像/这样的ASCII字符不会被错误地编码字节中的und

此外,java将字符串文本、类和方法名称作为UTF-8存储在.class文件中。 UTF-8是一种多字节编码

//  byte[] bytes = new byte[] { (byte) 0xD8, 0x34, (byte) 0xDD, 0x1E };
String text = "The method 
Character.toChars(int)
will give you the UTF-16 series of code units corresponding to that code point.

So, for your example:

System.out.println("Character is " + new String(Character.toChars(65536))); //equivalent to U+10000
  • UTF-8将7位ASCII码点作为子集,字节序列(字节)0x63实际上是码点U+0063,也称为“c”
  • UTF-16有很大一部分Unicode作为子集:字符
    \u10000
    实际上是代码点U+10000
因此,使用
char
值始终是部分解决方案。最好使用代码点

答案是:

System.out使用默认平台编码,不能表示所有Unicode。此外,控制台字体必须能够描述代码点。当无法转换时,通常会显示
占位符


解决方案是写入UTF-8格式的文件。然后用UTF-8格式打开文件,比如说使用记事本++,然后安装一个巨大的Unicode字体。

@NonymousNT Oops,对不起,我误解了您要查找的内容。我的编辑是否澄清了问题?