Eclipse encoding

2019-08-06 02:40发布

问题:

I set my eclipse default encoding by trying: Windows > Preferences > General > Content Types, set UTF-8 as the default encoding for all content types. Windows > Preferences > General > Workspaces, set "Text file encoding" to "Other : UTF-8".

Then we I import some projects, it always mess up some characters:

                    case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
        case 'y':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
        case '�':
    }

What should I do? Any ideas?

回答1:

Two things maybe happening:

  1. Some projects (even folders and/or files) may have their own specific charset which could be different to the whole workspace-level charset preference. You could right-click on the specific file and do Properties -> Resource to check which text file encoding is really being used (Default computed or Other). As additional info, this Resource specific preferences are stored in the ./settings/org.eclipse.core.resources.prefs file of the project.

  2. If the computed charset is UTF-8, the file you are viewing in the Java editor is not really coded in UTF-8. To verify that, you could check those characters in a hexadecimal editor, and use this useful UTF-8 table to compare the expected UTF=8 hex value in the table and the actual value the hex editor shows you it has.



回答2:

Did you try to change the .java file encoding from Eclipse (right click on the .java file -> Properties -> Resource -> Text file encoding)?