Solution to Garbled text after Entering Chinese characters in the eclipse Console

Source: Internet
Author: User

Recently, I encountered a problem that my eclipse cannot correctly display Chinese characters, as shown below:

1. Read the Chinese characters of a file and output it to the console. garbled characters are found;

2. output to the console through system. Out. There is no problem, but the Chinese output to the console is re-read, garbled;

3. Enter the content in the console, and then write the content into a file.

I thought there was a problem with the Chinese encoding settings of my Eclipse, but after all the changes, I found that the problem still exists. The system also supports Chinese, and there is no problem with the settings. In this caseProgramYes. So I wrote such a simpleCode:

 
Bufferedreader reader =NewBufferedreader (NewInputstreamreader (system. In); system. Out. println (reader. Readline (); reader. Close ();

Check whether my console is faulty and the result is garbled. There are only two possible problems:

1. system. In has a problem;

2. There is a problem with reader. Readline.

Reader. readline () is not a problem for the time being, because bufferedreader is dedicated to reading characters, but here I have an inputstreamreader that reads bytes and occupies two bytes for Chinese characters, however, inputstreamreader reads only one byte at a time. If the number of Chinese characters is odd, garbled characters may occur.

There are many methods on the Internet, such as specifying the Chinese encoding format. I have tried it. Finally, I found a method. The test is feasible. The method is as follows:

(1) Disable eclipse;

(2)in the same directory of eclipse.exe, there is an eclipse. ini, open it, and then add the following sentence:

-Dfile. Encoding = UTF-8

Save;

(3) re-open eclipse and the problem will disappear.

-Dfile. Encoding = UTF-8, which literally means to set the system attribute file. encoding to UTF-8.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.