The solution to the eclipse Chinese garbled problem and a situation where the garbled code cannot be solved

General garbled solution:

The reason why eclipse has garbled characters is because the encoding rules selected by the eclipse editor are variable. Generally, the default is UTF-8 or GBK. When a project is imported from the outside, if the encoding method of the project is different from the encoding method set in eclipse, Chinese garbled characters will occur. There are several situations.

If the encoding method of the entire imported project conflicts with the encoding method of eclipse, then all the Chinese in this project will be garbled; if the encoding method of all projects conflicts with the encoding method of the eclipse workspace, then all the Chinese in the project There may be garbled characters. For the eclipse workspace, eclipse will save the settings you changed in the setting file of the workspace. If you modify the encoding method of a single project, eclipse will save the encoding method in the .setting file package of the project.

Therefore, there are two principles to avoid Chinese garbled characters:

(1) Avoid frequently changing the workspace. It is best to carry out the project in one workspace from the beginning, and it is best to set the coding method of the workspace to the one you usually use most often or the project coding method specified by the company, so that the project The encoding method of the workspace will be used to avoid inconsistent encoding;

(2) Try to use the same encoding method for files of the same type to ensure that files of the same type can use consistent encoding settings;

To solve the problem of Chinese garbled characters, there are the following settings:


(1) Modify the encoding method of the workspace: 

Window->Preferences->General->Workspace->Text file Encoding 

Select the required encoding method in Others, and then save.

(2) Modify the encoding method of a single project: 

Right-click the project and select the last item "Properties" in the pop-up menu.

In the menu tree on the left of the new window that opens, select Resource (the first one), then find Text file encoding on the right, select "other", and select the desired encoding method in the drop-down box.

(3) Modify the encoding method of a class of files:

 Suppose you want to set the js file encoding method to UTF-8, you should Window->General->Content Types 

Select JavaScript Source File in Content Types, select *.js in the File associations column, then enter UTF-8 in the Default Encoding column, click Update, and save.

(4) Modify the encoding method of a single file: right-click the file to be modified, select the last item "Properties" in the pop-up menu, select Info (the first one) in the menu tree on the left of the opened new window, and then Find Text file encoding on the right, select "other", and select the required encoding method in the drop-down box. Similar to the method of modifying the engineering coding method.

ps: Another garbled problem encountered during the project is due to the font file problem of the operating system. In some cases, if the system Chinese font used by eclipse is damaged, it will also cause the problem that Chinese cannot be displayed. Therefore, if none of the above settings can solve the problem, you should consider the problem of the system font file.

Unable to solve the garbled situation (modify the content in the case of garbled characters):

1. When you open a file in eclipse and find garbled Chinese characters, you must not modify the content of this file. Once you change the content of this file, it is useless to modify the code, and you can only import it again.

2. When you open a file and find garbled characters, the first step is to close the file, then right click on the file, select properties, then select encoding, first select utf8, then confirm saving and open the file to check whether it is garbled characters, if it is still garbled characters, continue Close the file, right-click to select properties, select gbk in encoding, confirm to save and then open the file.

3. Basically, the above two methods can solve the garbled characters. Remember to close the file when modifying the encoding format, and the file content cannot be modified.

Guess you like

Origin blog.csdn.net/weixin_45813351/article/details/123916626