Reputation: 57968
How can I read international characters from console in java?
Upvotes: 3
Views: 527
Reputation:
I can't resolve the problem since I'm a beginner. I'd like to use UTF-8 charset. If I type the "aákú" (or any text with non english characters) the program will hangs up!
Scanner sc = new Scanner(System.in);
System.out.println("Please type any text:");
String text = sc.nextLine();
System.out.println("");
System.out.println(text);
The InputSream class make some result like System.in...
Upvotes: 1
Reputation: 1075059
If you can't for some reason use java.io.Console
as suggested by Michael Borgwardt, you can use an InputStreamReader
around System.in
, since System.in
is an InputStream
. You tell the InputStreamReader
what character set you're expecting to receive as part of construction, either via a Charset
or a CharsetDecoder
.
Upvotes: 2
Reputation: 346397
Using the java.io.Console
class, just like any other character. The question is whether the console itself supports those "international characters", but that has nothing to do with Java.
Upvotes: 4