简体   繁体   中英

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.

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 .

Are you specifying the right charset in the Scanner constructor ?

 public Scanner(InputStream source, String charsetName) 

Constructs a new Scanner that produces values scanned from the specified input stream. 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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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