How can I 开发者_如何学Cread international characters from console in java?
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.
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
.
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...
精彩评论