0

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?

Community
  • 1
  • 1
Christian
  • 6,070
  • 11
  • 53
  • 103
  • I never had a problem with different encodings in different files, but I was far from having your size of project. – user1803551 Oct 12 '14 at 12:28
  • Will Java compile just fine, or will I have to specify command line options, in your experience? – Christian Oct 12 '14 at 12:40
  • 1
    Everything was fine as-is using eclipse. The case I dealt with was one file with Chinese and Hebrew characters which eclipse had to save in UTF (don't remember 8 or 16), and the other files were in the default encoding. If you have something more complicated then I don't know what could happen. – user1803551 Oct 12 '14 at 12:50

1 Answers1

1

Yes you can.

You can choose the default encoding to use for the whole Eclipse project:

  • right click on a project
  • resource part
  • Text file encoding zone, check Other and choose UTF-8 (or what you want) in the combo

You can also change the encoding for a particular file:

  • right click on the file
  • resource part
  • Text file encoding zone, check Other and choose UTF-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.

Nicolas Albert
  • 2,586
  • 1
  • 16
  • 16