Issue
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.
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.
Answered By - Jon Skeet
Answer Checked By - Gilberto Lyons (JavaFixing Admin)