问题
I know Java uses UTF-16 internally and expects .properties files to be in ISO-8859-1 by default.
I'm currently working on a project that was written in Eclipse, whose default encoding on our systems is cp-1252. I'm thinking utf-8 would be a much more sensible option, going forward.
However, given the scale of the project (it's split up into modules and uses libraries from all over the place), I can't just batch-convert all source code files in one go.
Will Java have a problem with some files in a project being in one encoding and some in another? (Clearly, having entire libraries written in encodings that are different from one another doesn't seem to be a problem - probably because they are all UTF-16 once compiled, anyway.)
Would Eclipse be able to handle that (i.e. different encodings per file) correctly?
回答1:
Yes you can.
You can choose the default encoding to use for the whole Eclipse project:
- right click on a project
resource
partText file encoding
zone, checkOther
and chooseUTF-8
(or what you want) in the combo
You can also change the encoding for a particular file:
- right click on the file
resource
partText file encoding
zone, checkOther
and chooseUTF-8
(or what you want) in the combo
Preferences are store in the hidden folder .settings
in your project. File encoding preferences are store in the .settings/org.eclipse.core.resources.prefs
.
Thoses preferences can be commited using your favorite source control and shared with other developpers.
来源:https://stackoverflow.com/questions/26324708/can-source-code-files-with-different-encoding-coexist-in-the-same-java-projec