Getting Unicode Values ​​from System.in

I created Scannerone that gets input from System.inso that I can get input from the console.

Scanner scanner = new Scanner(System.in, "UTF-8");

When i do

String s = scanner.next();

and then type דברin the console, the string value will become ???? ???.

The console can display Unicode characters, but why can't I read them?

+5
source share
2 answers

It is unsafe to assume that it is System.inencoded in UTF-8 encoding. See this question for some workarounds.

+2
source

This is because System.in returns text in the default encoding (your default encoding is obviously not UTF-8). This should work fine.

Scanner sc = new Scanner(System.in);
String s = sc.next();
System.out.println(s);

Java

System.out.println(System.getProperty("file.encoding"));
+1

All Articles