0

i have simple console program in java, i try to get input from user the input is in Hebrew "שלום" but when i tried to read it i get ???? , but i wish to get "שלום" , how is the best way?

my code:

   public static void main(String[] args)  {

    String s;
    Scanner in = new Scanner(System.in);
    System.out.println("Enter a string");
    s = in.nextLine();
    System.out.println(s);
}

}

output:

run:

Enter a string

שלום

????

BUILD SUCCESSFUL (total time: 5 seconds)

i know that i should use utf-8 but i really dont know how... any help?

Maor Avitan
  • 207
  • 1
  • 3
  • 10
  • 4
    Possible duplicate of [Scanner in JAVA outputs gibberish instead of Hebrew](http://stackoverflow.com/questions/18725603/scanner-in-java-outputs-gibberish-instead-of-hebrew) – Maximilian Gerhardt Feb 02 '16 at 22:09
  • ok.. so how do i do it? thanks – Maor Avitan Feb 02 '16 at 22:16
  • Maybe this can be helpful, System.out.println(Arrays.toString(s.getBytes("UTF-8"))) – Roman Feb 02 '16 at 22:22
  • 2
    Since I've marked the question as a duplicate of another question, you will find the answer to your question there. Hint: Start using a `InputReader` initialized with `new InputStreamReader(System.in, StandardCharsets.UTF_8)`, with this you can control the encoding of the characters until you hit the right encoding. For the console settings in an IDE like Eclipse, have a look at https://stackoverflow.com/questions/17385818/eclipse-character-encoding . – Maximilian Gerhardt Feb 02 '16 at 22:34
  • I use netbeans and it configured to utf-8, so I assume that it is not a configuration problem. – Maor Avitan Feb 02 '16 at 22:47
  • Scanner can be instantiated with a character set as well, say it's UTF-8 there, I believe – Scott Sosna Feb 03 '16 at 02:05

1 Answers1

0

If you are using windows you need to check the terminal encoding.

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.