Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

Problem: Scanner in JAVA outputs gibberish instead of Hebrew.

If you want to get an input in Hebrew via the command line or powershell, You need to check the terminal encoding on your Windows PC.

To do this just type chcp in the console

as output you should see chcp 28598

if you see diffrent number type chcp 28598

Now your console encoding is set to hebrew

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top