JAVA中的扫描仪输出乱码而不是希伯来语 [英] Scanner in JAVA outputs gibberish instead of Hebrew

查看:104
本文介绍了JAVA中的扫描仪输出乱码而不是希伯来语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Netbeans中扫描希伯来语时遇到问题. 我正在尝试扫描用户的输入并显示在控制台中,但是它显示为乱码.

我的代码是:

 public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Please input:");
    System.out.println("Your input is: " + input.next());
}

这是控制台:

运行:

请输入:

שלום

您的输入是:

成功完成(总时间:3秒)

相同的代码可以在Eclipse上完美运行. 如果我使用Println()希伯来语单词,它也可以正常工作,所以这不是编码问题. (我正在使用Netbeans 7.3.1)

非常感谢您,

巴拉克.

解决方案

调用

and this is the Console:

run:

Please input:

שלום

Your input is: ����

BUILD SUCCESSFUL (total time: 3 seconds)

The same exact code works perfectly on Eclipse. If I Println() a hebrew word it also works fine, so it's not an encoding problem. (I am using Netbeans 7.3.1)

Thank you very much,

Barak.

解决方案

When you call Scanner(InputStream), that will use the platform default encoding to convert the bytes from the stream into text.

I suspect you simply need to work out what encoding your console is using, and use that either to construct an InputStreamReader around System.in to start with, or pass the encoding name as a second argument to the constructor.

这篇关于JAVA中的扫描仪输出乱码而不是希伯来语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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