Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting unicode values from System.in

I have created a Scanner that gets input from System.in so 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 input Слово דבר in the console, the value of the string becomes ???? ???.

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

like image 947
Peter Olson Avatar asked Oct 21 '22 12:10

Peter Olson


1 Answers

It's not safe to assume System.in is UTF-8 encoded. See this question for some workarounds.

like image 190
Daniel Lubarov Avatar answered Oct 31 '22 13:10

Daniel Lubarov