Java、UTF-8 和 Windows 控制台 [英] Java, UTF-8, and Windows console

查看:24
本文介绍了Java、UTF-8 和 Windows 控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们尝试在 Windows 上使用 Java 和 UTF-8.应用程序在控制台上写入日志,我们希望使用 UTF-8 格式的日志,因为我们的应用程序具有国际化的日志.

We try to use Java and UTF-8 on Windows. The application writes logs on the console, and we would like to use UTF-8 for the logs as our application has internationalized logs.

可以将 JVM 配置为生成 UTF-8,使用 -Dfile.encoding=UTF-8 作为 JVM 的参数.它工作正常,但 Windows 控制台上的输出是乱码.

It is possible to configure the JVM so it generates UTF-8, using -Dfile.encoding=UTF-8 as arguments to the JVM. It works fine, but the output on a Windows console is garbled.

然后,我们可以将控制台的代码页设置为 65001(chcp 65001),但是在这种情况下,.bat 文件不起作用.这意味着当我们尝试通过我们的脚本(名为 start.bat)启动我们的应用程序时,绝对没有任何反应.命令简单返回:

Then, we can set the code page of the console to 65001 (chcp 65001), but in this case, the .bat files do not work. This means that when we try to launch our application through our script (named start.bat), absolutely nothing happens. The command simple returns:

C:Application> chcp 65001
Activated code page: 65001
C:Application> start.bat

C:Application>

但是没有chcp 65001,没有问题,可以启动应用.

But without chcp 65001, there is no problem, and the application can be launched.

对此有任何提示吗?

推荐答案

Try chcp 65001 &&start.bat

chcp 命令更改代码页,65001 是 Windows 7 及更高版本下 UTF-8 的 Win32 代码页标识符.代码页或字符编码指定如何将 Unicode 代码点转换为字节序列或再次转换回来.

The chcp command changes the code page, and 65001 is the Win32 code page identifier for UTF-8 under Windows 7 and up. A code page, or character encoding, specifies how to convert a Unicode code point to a sequence of bytes or back again.

这篇关于Java、UTF-8 和 Windows 控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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