Resolving garbled cases caused by default encoding conflicts between Java file encoding and Windows7 system (Chinese version)

Source: Internet
Author: User

Let's start with a simpler but also more egg-sore question.

background : I am a novice small white, beginner java.

problem : Compile a problem when writing Java files using UTF-8 encoded format.

Reason Analysis : 1, Java file Encoding format is UTF-8,WINDOWS7 system (the default encoding format is GBK) on the JDK to see, so error;

2, the first line should be public class P position turned into two wonderful Chinese characters, resulting in unresolved.

Workaround :

On the first question: Under the Windows7 system, create a new system variable (right-click on the Computer icon--Properties--left "advanced system Settings"--"advanced" environment variable--system variable--new), the variable is named Java_tool_options, The value of the variable is-dfile.encoding=utf-8. This way, each time you execute a Java class tool, the encoding format is temporarily set to UTF-8 (but you will not understand the corresponding error message), so this method is best to confirm that there are no other problems in addition to coding problems with OH).

On the second question: These two wonderful Chinese characters are actually due to Windows Notepad (well, I don't have to write Java anymore.) The default encoding format is ANSI, and turning into UTF-8 is not a purely UTF-8, but a "utf-8+bom" format. Yes, this BOM is the cause of the error. The recommended solution is to use the IDE class tool such as Eclipse, or a text editor such as EditPlus (simply say EditPlus this, in the tool-configuration (user) Customization Tool-left click on the file option, the right side can set the default format of the text, select UTF-8 on it).

Resolving garbled cases caused by default encoding conflicts between Java file encoding and Windows7 system (Chinese version)

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.