如何更改 Eclipse 中的默认文本文件编码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3751791/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:38:03  来源:igfitidea点击:

How to change default text file encoding in Eclipse?

eclipse

提问by PawelRoman

Whenever I add a new html file (or other text file) to the project its encoding is set to Cp1250. I am not sure why, I guess this is probably because my default language in Windows is Polish and I don't want to change it. Anyway, Eclipse says that Cp1250 is a 'default' encoding and I have to manually change it to UTF-8 each time I add anything.

每当我向项目添加新的 html 文件(或其他文本文件)时,其编码设置为 Cp1250。我不知道为什么,我想这可能是因为我在 Windows 中的默认语言是波兰语,我不想更改它。无论如何,Eclipse 说 Cp1250 是“默认”编码,每次添加任何内容时我都必须手动将其更改为 UTF-8。

So where can I change the default encoding to UTF-8? I've set the encoding by right-clicking on whole project but it didn't help. I can't find anything in options. It's so annoying...

那么在哪里可以将默认编码更改为 UTF-8?我通过右键单击整个项目来设置编码,但没有帮助。我在选项中找不到任何东西。太烦人了...

I'm using 'Helios' release of the eclipse and use it with pydev if that matters.

我正在使用 Eclipse 的“Helios”版本,如果重要的话,将它与 pydev 一起使用。

回答by nanda

Window -> Preferences -> General -> Workspace : Text file encoding

窗口 -> 首选项 -> 常规 -> 工作区:文本文件编码

回答by BiAiB

Nanda's answer wasn't enough in my setup. What I needed to do is:

Nanda 的回答在我的设置中还不够。我需要做的是:

  • Window > Preferences > General > Content Types
  • Select Text > HTML in the tree
  • Select all file associations, particularly .html
  • Input "UTF-8" in the text-field "default encoding"
  • 窗口 > 首选项 > 常规 > 内容类型
  • 在树中选择 Text > HTML
  • 选择所有文件关联,尤其是 .html
  • 在文本字段“默认编码”中输入“UTF-8”

回答by vanduc1102

For eclipse Mars:

对于月食火星

Change Workspace Encoding:

更改工作区编码:

Change workspace encoding

更改工作区编码

Check a file Encoding: Image check a file encoding

检查文件编码: 图像检查文件编码

回答by Merphys

Preferences >> General >> Editors >> Text editors >> Spelling: Enconding

Preferences >> General >> Editors >> Text editors >> Spelling: E​​nconding

P.S.: Eclipse Indigo and Juno.

PS:Eclipse Indigo 和 Juno。

回答by Radek Pech

If you need to edit files of same type with more encodings in different folders and projects (e.g. one project is in UTF-8 and other in Windows-12xx), go to Window > Preferences > General > Content Types > Text> and select each type with multiple encodings.

如果您需要在不同的文件夹和项目中编辑具有更多编码的相同类型的文件(例如,一个项目采用 UTF-8,另一个项目采用 Windows-12xx),请转到“窗口”>“首选项”>“常规”>“内容类型”>“文本”> 并选择每个具有多种编码的类型。

For each type delete content of the Default encodingand click Update.

对于每种类型,删除默认编码的内容,然后单击更新

This way Eclipse will not "autodetect" encoding and will use encoding set for project or folder.

这样 Eclipse 就不会“自动检测”编码,而是使用项目或文件夹的编码集。

回答by Felipe Martins

I was having the same problem when I received a html to put inside my project and rename it to .jsp. To solve the problem, I needed to what people above already said, that is, to change text encoding in Eclipse Preferences. However, before renaming the files to .jsp, it was necessary to include the following line in the beginning of each .html file:

当我收到一个 html 以放入我的项目并将其重命名为 .jsp 时,我遇到了同样的问题。为了解决这个问题,我需要上面人已经说过的,即在Eclipse Preferences中更改文本编码。但是,在将文件重命名为 .jsp 之前,必须在每个 .html 文件的开头包含以下行:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

I believe this forced Eclipse to understand that it was necessary to change file encoding when I tried to rename .html to .jsp.

我相信这迫使 Eclipse 明白,当我尝试将 .html 重命名为 .jsp 时,有必要更改文件编码。

回答by Alcides

What worked for me in Eclipse Mars was to go to Window > Preferences > Web > HTML Files, and in the right panel in Encoding select ISO 10646/Unicode(UTF-8), Apply and OK, then and only then my .html files were created with .

在 Eclipse Mars 中对我有用的是转到Window > Preferences > Web > HTML Files,然后在 Encoding 的右侧面板中选择ISO 10646/Unicode(UTF-8),Apply 和 OK,然后只有我的 .html 文件是用 .

回答by rghome

To change the default encoding used for all workspaces you can do the following:

要更改用于所有工作区的默认编码,您可以执行以下操作:

Create a defaults.inifile in the Eclipse configuration folder. For example, if Eclipse is installed in C:/Eclipsecreate C:/Eclipse/configuration/defaults.ini. The file should contain:

在 Eclipse 配置文件夹中创建一个defaults.ini文件。例如,如果 Eclipse 安装在C:/Eclipsecreate 中C:/Eclipse/configuration/defaults.ini。该文件应包含:

org.eclipse.core.resources/encoding=UTF-8

If you want to set the line terminator to UNIX values you can also add:

如果要将行终止符设置为 UNIX 值,还可以添加:

org.eclipse.core.runtime/line.separator=\n

In eclipse.iniin the Eclipse install folder (e.g., C:/Eclipse) add the following lines:

在Eclipse 安装文件夹(例如)的eclipse.ini中,C:/Eclipse添加以下几行:

-plugincustomization 
D:/Java/Eclipse/configuration/defaults.ini

You might need to play around with where you put it. Inserting it before the "-product" option seemed to work.

您可能需要摆弄放置它的位置。在“-product”选项之前插入它似乎有效。

回答by moueza

Window>Preferences>Web>JSP files

窗口>首选项>Web>JSP 文件