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 file name using Scanner.
Scanner sc = new Scanner(System.in,"utf-8");
System.out.println("Encoding is :" + Charset.defaultCharset());
System.out.println("Enter the path:");
inputFilePath = sc.nextLine();
and if my input is for eg - 漢字
When I print the file name my output is
Encoding is :UTF-8
Input File Path:æ¼¢å—
I also tried,
byte[] jis = sc.nextLine().getBytes("Shift_JIS");
System.out.println(new String(jis));
and My output was
Input File Path:??��??�\
How can I rectify this?
Eclipse
is reading from the Console which is set by default as UTF-8. To read the data you need to change the console encoding to Japanese supported encoding.
In the Run Configuration, change the encoding to Japanese supported encoding and try again.
yes, when I changed the encoding to UTF-16BE or UTF-16LE, I am able to view the japanese input.Thanks a lot!
This is misleading, UTF-8 does support Japanese (And any language for that matter) and should be preferred over legacy encodings such as Shift-JIS