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
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.
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 !!
This Answer for Chinese
Every String is already (conceptually) a sequence of characters, including Chinese characters.. Encoding only comes into it when you need to convert it into a bytes, which you don't need to for your assignment. Just use the String's hashcode. In fact, when you create a HashMap, that's exactly what will happen behind the scene