扩展Ascii不在控制台中工作! [英] Extended Ascii doesn't work in console!

查看:172
本文介绍了扩展Ascii不在控制台中工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如
System.out.println(╚);
显示为?,同样适用于System.out.println(\\\╚);

For example System.out.println("╚"); displays as a ?, same goes for System.out.println("\u255a");

为什么这不工作? Stdout确实支持这些字符,所以我不能得到它。

Why doesn't this work? Stdout does indeed support these characters so I don't get it.

推荐答案

参见此问题。当Java的默认字符编码不是UTF-8时 - 看起来,在Windows和OS X上,而不是Linux - 那么未能编码的字符将转换为问号。你可以传递正确的开关( -Dfile.encoding = UTF-8 在一些终端,但我没有在我前面的Windows框)到JVM的命令行,或者您可以设置环境变量。轻易地确定这应该是什么可能是不可能的,但如果你知道你将总是运行在Win32控制台,例如,你可以选择 Charset 在将字符写入标准输出之前对字符进行显式编码,或者您可以直接写入所需的字节。

See this question. When Java’s default character encoding is not UTF-8 — as is the case, it seems, on Windows and OS X, but not Linux — then characters which fail to encode are converted to question marks. You can pass the correct switch (-Dfile.encoding=UTF-8 on some terminals, but I don’t have a Windows box in front of me) to the JVM’s command line, or you can set an environment variable. Portably determining what this should be might be impossible, but if you know that you will always run on the Win32 console, for example, you can choose a Charset to explicitly encode the characters before writing them to standard output, or you can directly write the bytes you need.

这篇关于扩展Ascii不在控制台中工作!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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