Read Japanese Character using Scanner

后端 未结 3 1927
醉梦人生
醉梦人生 2021-01-15 01:41

Possible duplicate: How can I read Chinese characters correctly using Scanner in Java?

My input file name may have japanese characters and I am trying to read the fi

3条回答
  •  不要未来只要你来
    2021-01-15 02:24

    Your code is correct, only issue is you are reading utf-8 and then converting it to Shift_JIS which prints junk characters.

    Have you tried using this.

    Scanner sc = new Scanner(System.in,"utf-8");
    System.out.println("Encoding is :" + Charset.defaultCharset());
    
    System.out.println("Enter the path:");
    String inputFilePath = sc.nextLine();
    System.out.println("Input path:" + new String(inputFilePath.getBytes("utf-8")));
    

    Hope this helps !!

提交回复
热议问题