输出非utf8符号到控制台 [英] Output non-utf8 symbols to console

查看:214
本文介绍了输出非utf8符号到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中编写了非常简单的控制台应用程序。

I am writing very simple console application in Java.

问题是,我需要输出西里尔和爱沙尼亚语非utf8符号到控制台,但在Windows中我得到一堆奇怪的符号,在MacOsX我只得到?? ??

The problem is that I need to ouput cyrillic and estonian non-utf8 symbols to console, but in Windows I get bunch of strange symbols and in MacOsX I get only ???? instead of something more readable.

如何实现我的目标?

- UPDATE 1 -

地区给了我:


LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

似乎我困扰着UTF-8的东西%)

Seems I am stuck with that UTF-8 thing %)

奇怪的想法:

有没有办法从eclipse获取控制台,并在eclipse之外使用?

Is there any way to get a console from eclipse and use it outside of eclipse?

推荐答案

Windows终端:终端程序 cmd.exe 编码作为操作系统的其余部分,并且从Java你没有办法知道你是否从终端运行。您必须将 cmd.exe 使用的字体设置为Lucida控制台,然后切换code page chcp 之前运行程序:

Windows Terminal: The terminal program, cmd.exe, doesn't use the same encoding as the rest of the OS, and from Java you have no way of knowing if you are being run from a terminal or not. You have to set the font used by cmd.exe to Lucida Console and switch the "code page" with chcp before running the program:

  • Cyrillic: use chcp 1251
  • Estonian: probably you need chcp 1257

OS X终端:据我所知终端配置为UTF-8,所以你可以只使用UTF-8。使用 locale 命令检查编码。

OS X Terminal: as far as I know the terminal is configured for UTF-8, so you can just use UTF-8. Use the locale command to check your encoding.

这篇关于输出非utf8符号到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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