从 Windows 控制台中的 Java 代码问题打印出 unicode [英] Printing out unicode from Java code issue in windows console

查看:29
本文介绍了从 Windows 控制台中的 Java 代码问题打印出 unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 控制台中打印出 unicode 符号时遇到问题.

I have got a problem with printing out a unicode symbol in the windows console.

这是打印出unicode符号值的java代码;

Here's the java code that prints out the unicode symbol value;

System.out.print("u22A2 ");

当我在 Eclipse 中以 UTF-8 编码设置运行程序时,问题不存在,但是当涉及到 Windows 控制台时,符号被问号替换.

The problem doesn't exist when I run the program in Eclipse with encoding settings as UTF-8, however when it comes to windows console the symbol gets replaced by a question mark.

为了克服这个问题,做了以下工作,但没有成功;

The following was done to try overcome this problem, with no success;

  • 将 windows 控制台的字体更改为 Lucida 控制台.

  • Change the font of windows console to Lucida Console.

每次运行 Windows 控制台时,我都会更改编码设置,即使用 chcp 65001

Every time I run windows console I will change the encoding settings, i.e. with the use of chcp 65001

我尝试了几次的额外步骤是运行带有参数的 java 文件,即 java -Dfile.encoding=UTF-8 Filter(其中Filter"是类的名称)

An extra step I've tried a few times was running the java file with an argument, i.e. java -Dfile.encoding=UTF-8 Filter (where "Filter" is name of the class)

推荐答案

默认情况下,Windows CMD 中使用的代码页是 437.您可以通过在提示符下运行此命令来进行测试:

By default, the code-page using in the CMD of Windows is 437. You can test by run this command in the prompt:

C:>chcp
Active code page: 437

而且,此代码页会阻止您正确显示 Unicode 字符!为此,您必须将代码页更改为 65001 并使用 -Dfile.encoding=UTF-8.

And, this code-page prevent you from showing Unicode characters properly! You have to change code page to 65001 AND using -Dfile.encoding=UTF-8 for that purpose.

C:>chcp 65001
Active code page: 65001
C:>java -jar -Dfile.encoding=UTF-8 path/to/your/runnable/jar

这篇关于从 Windows 控制台中的 Java 代码问题打印出 unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆