本文介绍了如何使用Java将Unicode符号U + 2610和U + 2612打印到Windows控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做什么:

public class Main {
    public static void main(String[] args) {
        char i = 0x25A0;
        System.out.println(i);
        i = 0x2612;
        System.out.println(i);
        i = 0x2610;
        System.out.println(i);
    }
}

我在IDE中得到的东西:我在IDE中得到的东西

What I get in IDE:What I get in IDE

我在Windows控制台中得到了什么:我在Windows控制台中得到的内容

What I get in Windows console:What I get in Windows console

我有Windows 10(俄语语言环境),控制台中的Cp866默认编码,IDE中的UTF-8编码.如何使控制台中的字符看起来正确?

I have Windows 10 (Russian locale), Cp866 default coding in console, UTF-8 coding in IDE.How to make characters in console look correct?

推荐答案

实际上有两个问题:

  1. Java通常将输出转换为其默认编码,该默认编码与控制台编码无关.显然,这只能在VM启动时使用例如

  1. Java converts output to its default encoding which doesn't have anything to do with the console encoding, usually. This can apparently only be overridden at VM startup with, e.g.

java -Dfile.encoding=UTF-8 MyClass

  • 控制台窗口必须使用TrueType字体才能显示Unicode.但是,Consolas和Lucida Console都没有☐或☒.因此,它们显示为带有Lucida Console的框,以及带有问号的Consolas框(即缺失字形字形).输出仍然很好,您可以轻松地复制/粘贴它,看起来不正确,并且由于Windows控制台不使用字体替换(无论如何都很难用字符网格进行替换),因此您几乎无能为力使它们显示出来.

  • The console window has to use a TrueType font in order to display Unicode. However, neither Consolas, nor Lucida Console have ☐, or ☒. So they show up as boxes with Lucida Console and boxes with a question mark with Consolas (i.e. the missing glyph glyph). The output is still fine, you can copy/paste it easily, it just doesn't look right, and since the Windows console doesn't use font substitution (hard to do that with a character grid anyway), there's little you can do to make them show up.

    我可能只会使用 [█] [] [X] .

    这篇关于如何使用Java将Unicode符号U + 2610和U + 2612打印到Windows控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-04 02:30