如何在Java中打印非ASCII字符?

huangapple go评论84阅读模式
英文:

How to print non-ascii character in java?

问题

class P1
{
    public static void main(String[] args)
    {
        System.out.println("在命令提示符中只显示一个问号...");
        如果您知道,请帮忙解决。
    }
}
英文:
class P1
{
    public static void main(String[] args)
    {
        System.out.println("¢");
    }
}

it comes as only one question mark in command prompt...if you know then please help me out.

答案1

得分: 3

Your terminal does not support UTF-8, you're most likely running Windows. Google to see how to change that.

英文:

Your terminal does not support UTF-8, you're most likely running Windows. Google to see how to change that.

答案2

得分: 1

问题几乎肯定与您的默认控制台/IDE可以显示的字符有关。即使在屏幕上显示,UTF 字符也需要启用 UTF 的字体才能正确呈现。

在 GitHub 上可能有一些Java UTF文本编辑器,您可以将其用作控制台替代品。然后,您需要一个OutputStream,它将附加到文本编辑器面板(我多年前创建了类似的东西:https://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/TextAreaOutputStream.java),然后您需要使用

System.setOut

System.setErr

与您的流一起使用。

英文:

The problem is almost certainly with the characters your default console/ide can display. Even when displayed on the screen, utf characters need a utf enabled font for them to render correctly.

There are probably Java UTF text editors on GitHub that you could use as a console replacement. Then what you need is an OutputStream that will append to the text editor panel (I created something of this ilk years ago: https://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/TextAreaOutputStream.java) and then you need to use

System.setOut

and

System.setErr

With your Stream

huangapple
  • 本文由 发表于 2020年8月13日 01:24:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63381769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定