在 Eclipse 中一次更改多个文件的文本编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/705279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change text encoding for multiple files at once in Eclipse
提问by Tomas Andrle
I have some UTF-8 HTML templates in my Eclipse project and Eclipse keeps treating them as if they had a different encoding. It says the encoding is "determined from content". I want to force the correct encoding.
我的 Eclipse 项目中有一些 UTF-8 HTML 模板,Eclipse 一直将它们视为具有不同的编码。它说编码是“由内容决定的”。我想强制使用正确的编码。
I can force it for a single file but setting an encoding for the parent folder won't affect the files in it because instead of the "inherit" option in the property sheet there's the "determined from content" thing in it's place.
我可以将它强制用于单个文件,但为父文件夹设置编码不会影响其中的文件,因为它不是属性表中的“继承”选项,而是“根据内容确定”的东西。
Is it possible to set the encoding for all files in a Project at once?
是否可以一次为项目中的所有文件设置编码?
采纳答案by arty
I've just solved this problem (eclipse 3.5.2)
我刚刚解决了这个问题(eclipse 3.5.2)
Two steps required:
需要两个步骤:
- Change text file encoding on the folder property page(.setting/org.eclipse.core.resources.prefs file has been created in my project)
- Change default encoding on *.html file content type on the Preference page General/Content Types
- 更改文件夹属性页上的文本文件编码(我的项目中已创建.setting/org.eclipse.core.resources.prefs 文件)
- 在首选项页面常规/内容类型上更改 *.html 文件内容类型的默认编码
回答by Joachim Sauer
I've only seen "determined from content" for XML files. In that case it's the only correct setting, because XML files have their encoding defined in their header, so forcing anything else would be a grave mistake.
我只见过 XML 文件的“由内容决定”。在这种情况下,这是唯一正确的设置,因为 XML 文件在其标头中定义了其编码,因此强制执行其他任何操作将是一个严重的错误。
If you still want to do it, you could try to view the file .settings/org.eclipse.core.resources.prefs
in your project (that file may or may not exist dependin on wether you've manually set any encoding in the project or not).
如果您仍然想这样做,您可以尝试查看.settings/org.eclipse.core.resources.prefs
项目中的文件(该文件可能存在也可能不存在,具体取决于您是否在项目中手动设置了任何编码)。
回答by Tomas Andrle
This was caused by a development version of Eclipse. In the latest official release (3.5) it is fixed.
这是由 Eclipse 的开发版本引起的。在最新的官方版本 (3.5) 中已修复。