简体   繁体   English

为什么我看不到Java中的Unicode字符

[英]Why I can't see the Unicode characters in Java

I am learning java and I found out that in java char ranges from 0-65536 and java uses Unicode to represent characters. 我正在学习Java,发现在Java中char的范围是0-65536,而Java使用Unicode表示字符。 So, I run the following code to see what all the characters are: 因此,我运行以下代码来查看所有字符是什么:

class A{
    public static void main(String args[]){
        char x=0;
        for(int i=0;i<65536;i++){
            x++;
            System.out.println(i + "th character is: " + x);
        }
    }
}

what I found is :- 我发现的是:

  1. First 126 characters are same as ASCII characters. 前126个字符与ASCII字符相同。

  2. After 126th character it is just showing '?' 在第126个字符之后,它仅显示“?” mark. 标记。

Output:- 输出:-

... ...
127th character is: ? 第127个字符是:
128th character is: ? 第128个字符是:
129th character is: ? 第129个字符是:
130th character is: ? 第130个字符是:
131th character is: ? 第131个字符是:
132th character is: ? 第132个字符是:
133th character is: ? 第133个字符是:
... ...
65534th character is: ? 第65534个字符是:

My question is why it is showing '?' 我的问题是为什么它显示“?” mark instead of the Unicode characters. 标记而不是Unicode字符。

Check your file encoding with the following line and see what comes up. 使用以下行检查文件编码,然后看看会发生什么。 If not 'UTF-8' then set it correctly. 如果不是'UTF-8',请正确设置。 Still you wont see all of the char printed. 仍然您不会看到所有打印的字符。 So you need to see which one you want to set the file encoding accordingly. 因此,您需要查看要相应地设置文件编码的文件。

System.out.println(System.getProperty("file.encoding"));
System.setProperty("file.encoding","UTF-8");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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