System.out字符编码 [英] System.out character encoding

查看:162
本文介绍了System.out字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从命令行运行我的Java程序(Windows 7)。为了简化问题,我只描述相关的部分。

I'm running my Java program from command-line (Windows 7). To simplify matters, I describe only the relevant part.

public static void main(String[] args) {
    System.out.println("Árpád");
}

我的输出是垃圾。这显然是一个字符编码问题,á和á的匈牙利字符没有正确显示。我试过以下:

My output is garbage. It is obviously a character-encoding problem, the Hungarian characters of Á and á are not showing up correctly. I've tried the following:

public static void main(String[] args) {
    PrintStream ps = new PrintStream(System.out, true, "UTF-8");
    ps.println("Árpád");
}

但是我的输出仍然是垃圾。如何解决此字符编码问题与Windows 7命令行?感谢

But my output is still garbage. How can I resolve this character-encoding issue with Windows 7 command-line? Thanks

推荐答案

我通过从命令行找到正确的编码,然后使用 PrintStream 版本与该编码,,通过在命令行上指定并使用 System.out .println

I got your code to work by finding the right encoding from the command line, and then either using the PrintStream version with that encoding, or by specifying it on the command line and just using System.out.println.

要在命令行上找到编码,请运行 chcp 。这是我得到的输出:

To find the encoding on the commandline, run chcp. Here's the output I got:

Active code page: 850

这对应于Java字符集名称IBM850。因此,这将在命令行上创建正确的输出:

That corresponds to the Java charset name of "IBM850". So this then creates the right output on the command line:

java -Dfile.encoding=IBM850 Test

这篇关于System.out字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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