简体   繁体   English

Java Eclipse UTF-8 Hanzi字符问题?

[英]Java Eclipse UTF-8 Hanzi Character Issue?

I am working with a Scanner object and a few Chinese Hanzi characters to be displayed and processed as input. 我正在使用Scanner对象和一些中文汉字字符进行显示和处理,作为输入。

They appear from a println perfectly, but as I attempt to enter them for me scanner.next() call they simply change the color of the System.out.println output above and cause the program to lock up OR the scanner to stop accepting input upon ENTER . 它们完美地出现在println ,但是当我尝试为我输入它们时, scanner.next()调用它们只是更改了上面System.out.println输出的颜色,并导致程序锁定或扫描仪停止接受输入按ENTER键

Are you specifying the right charset in the Scanner constructor ? 您是否在Scanner构造函数中指定了正确的字符集?

 public Scanner(InputStream source, String charsetName) 

Constructs a new Scanner that produces values scanned from the specified input stream. 构造一个新的Scanner,该扫描器生成从指定输入流中扫描的值。 Bytes from the stream are converted into characters using the specified charset. 使用指定的字符集将流中的字节转换为字符。

Parameters: 参数:

  source - An input stream to be scanned charsetName - The encoding type used to convert bytes from the stream into characters to be scanned 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM