可以使用不同编码的源代码文件(同样)Java(Eclipse中的项目)共存? [英] Can source code files with different encoding coexist in (the same) Java (project in Eclipse)?

查看:435
本文介绍了可以使用不同编码的源代码文件(同样)Java(Eclipse中的项目)共存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Java使用 UTF-16内部,并期望 .properties 文件默认在ISO-8859-1中。



我目前正在使用Eclipse编写的项目,其在我们系统上的默认编码是cp-1252。我认为utf-8将是一个更加明智的选择。但是,考虑到项目的规模(分为模块和使用库),我不能只批量转换所有的源代码文件一次性。



Java会在一个项目中的某些文件中存在一些编码问题,另外一些是否有问题? (显然,整个图书馆编写的编码不一样,似乎并不是一个问题 - 可能是因为它们都是UTF-16编译的。)



Eclipse能否正确处理(即每个文件的不同编码)?

解决方案

是的,你可以。 p>

您可以选择用于整个Eclipse项目的默认编码:




  • right点击项目

  • 资源部分

  • 文本文件编码区域,检查其他并选择 UTF-8 (或您想要的)组合



您还可以更改特定文件的编码:




  • 右键单击文件

  • 资源部分

  • 文本文件编码区域,检查其他并选择 UTF-8 (或你想要的)在组合中



首选项存储在项目中的隐藏文件夹 .settings 中。文件编码偏好设置存储在 .settings / org.eclipse.core.resources.prefs 中。



Thoses首选项可以使用您最喜欢的源代码控制并与其他开发人员共享。


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?

解决方案

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.

这篇关于可以使用不同编码的源代码文件(同样)Java(Eclipse中的项目)共存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆