Scanner in JAVA outputs gibberish instead of Hebrew

末鹿安然 提交于 2020-01-05 12:08:48

问题


I have a problem with scanning Hebrew in Netbeans. I am trying to Scan the user's input and present in the Console, but it appears as Gibberish.

My code is:

 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());
}

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.


回答1:


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.



来源:https://stackoverflow.com/questions/18725603/scanner-in-java-outputs-gibberish-instead-of-hebrew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!