I want to input strings that may contain the letters åäö in Java, but Scanner converts them to some other character. I tried with utf-8 too:
String s1 = new Scanner(System.in).nextLine();
String s2 = new Scanner(System.in, "utf-8").nextLine();
System.out.println(s1 + "|" + (int)s1.charAt(0));
System.out.println(s2 + "|" + (int)s2.charAt(0));
System.out.println((int)'å' + "|" + (int)'?');
This yields:
å
å
?|8224
?|65533
229|63
All characters become 65533 with utf-8. Without utf-8, ä becomes 8222, ö becomes 8221, Å becomes 65533, Ä becomes 381, Ö becomes 8482.
Is there some alternative input method that allows for åäö?
I'm running java 8u25 and I'm running the program from the windows console.