I need to read input from the user, and I want to have support for non-latin letters, such as Å, Ä and Ö.
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"), true);
out.println(keyboard.readLine());
out.println("Read with charset: " + Charset.defaultCharset().name());
When I run this code, and input a latin letter it works as expected (I enter something, press enter and it prints out what I entered). But if I try with å I get this:
å
�
Read with charset: UTF-8
I have to hit enter twice if the text ends with a non-latin letter, and then it doesn't display them right. I have tried this in Netbeans' console, and in Windows command prompt and neither gives expected results.
I could not find a solution with UTF-8, but went with ISO-8859-1 instead. It worked with my Netbeans console (which should definitely be UTF-8) and in CMD when I first ran chcp 28591
, changed the font (it was necessary in my case) and ran my program.