使用扫描仪阅读日语字符 [英] Read Japanese Character using Scanner

查看:151
本文介绍了使用扫描仪阅读日语字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
我如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆