mkoryak
mkoryak

Reputation: 57968

How can I read international characters from console

How can I read international characters from console in java?

Upvotes: 3

Views: 527

Answers (3)

user300895
user300895

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

T.J. Crowder
T.J. Crowder

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

Michael Borgwardt
Michael Borgwardt

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

Related Questions