kien vu
kien vu

Reputation: 75

How can I get UTF-8 character from keyboard or remove it

I'm using the Scanner class as follows:

Scanner sc = new Scanner(System.in);
System.out.println(sc.nextLine());

It works ok, but if the input contains utf-8 characters the console cannot read them.

So how can I get utf-8 characters from the keyboard or set input without utf-8

Thanks so much.

Upvotes: 1

Views: 348

Answers (1)

Isma
Isma

Reputation: 15209

Try specifying the encoding and locale:

Locale locale = new Locale("vi" , "VN");
Scanner sc = new Scanner(System.in, "UTF-8");
sc.useLocale(locale);
System.out.println(sc.nextLine());

Upvotes: 1

Related Questions