About System.in read the data, print out the problem of code breaker

Source: Internet
Author: User

Online to find a lot of articles, and ultimately this article helped me solve the problem: http://blog.sina.com.cn/s/blog_5016ee390102e3xz.html (Thanks to the author of this article (*^__^*) hehe ... )

BufferedReader bf = new BufferedReader (new InputStreamReader (system.in));
String opertor = Bf.readline ();

String name1 = Bf.readline ();
System.out.println (NAME1);

This is a very common Java code to get keyboard input, but in the process of running, I found that as long as I entered the Chinese language, it is garbled.

Cause: Because the default character encoding for this open source project is UTF-8, the character encoding of my console is automatically changed to UTF-8, and the default format for the input stream of the keyboard is GBK format. This causes the odd garbled error (the explanation of this problem can be found in the search engine) in the process of GBK turning UTF-8.

Workaround:
1. Console encoding, Common (right), run configurations-R, right-click Code area
If this error occurs, the encoding format should be UTF-8, select Other, at this point there may be no GBK option, if not, then perform the operation after.

2. Change the text file encoding for the item, resource, properties, right-click, first adjust the text file encoding back to GBK, and then go back to reset console encoding encoding to GBK.

Many projects now require a unified character encoding before the start of the project to UTF-8, this is to better support internationalization, which can not avoid the console garbled this kind of comparison of the problem (at least I checked for a long time), so write it out for everyone to share ~

About System.in read the data, print out the problem of code breaker

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.