In VSCode , I cant input utf-8 String in java(with Scanner!)

Viewed 479

in java, i cant input String(with utf-8)

example

String str1 = "안녕하세요";
System.out.println("str1");

is print

안녕하세요

but

Scanner s = new Scanner(System.in);
//Scanner s = new Scanner(System.in,"UTF-8");
String str1 = "";
str1 = s.nextline();
//str = s.next();
System.out.println(str1);

is print

안녕하세요 << is typed by me
           << and it's print nothing(in fact " ")

how can i config my vscode terminal??

ps.when i typed eng, it worked well.

ps. i use this code

    public static void main(String[] args) throws UnsupportedEncodingException {
        String num;

        Scanner sc1 = new Scanner(System.in,"UTF-8");
        System.out.print("입력 : ");
        num = sc1.next();
        System.out.println(num);

        Scanner sc2 = new Scanner(new InputStreamReader(System.in, "UTF-8"));
        System.out.print("입력 : ");
        num = sc2.next();
        System.out.println(num);



        sc1.close();
        sc2.close();
    }

but its not work also

this is result

입력 : 안녕
��     
입력 : 안녕
��
1 Answers

you can use utf-8 in scanner like

Scanner console = new Scanner(new InputStreamReader(System.in, "UTF-8"));
Related