使用扫描仪阅读日语字符 [英] Read Japanese Character using Scanner
问题描述
可能的重复:
我如何使用Java中的扫描仪正确读取汉字?
我的输入文件名可能有日文字符,我正在使用扫描仪读取文件名。
Scanner sc = new Scanner(System.in,utf-8);
System.out.println(Encoding is:+ Charset.defaultCharset());
System.out.println(输入路径:);
inputFilePath = sc.nextLine();
如果我的输入是例如 - 汉字
当我打印文件名时,我的输出是
编码是:UTF-8
输入文件路径:我也尝试过,
$ b pre> byte [] jis = sc.nextLine()。getBytes(Shift_JIS);
System.out.println(new String(jis));
,我的输出是
输入文件路径:?? ?? \
我可以纠正这个吗?
Eclipse
正在从控制台默认设置为UTF-8。要读取数据,您需要将控制台编码更改为日语支持的编码。
在运行配置中,将编码更改为日语支持的编码,然后重试。 >
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.
这篇关于使用扫描仪阅读日语字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!