在Eclipse中使用utf-8文件 [英] Working with utf-8 files in Eclipse

查看:181
本文介绍了在Eclipse中使用utf-8文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相当直截了当的问题。有没有办法配置Eclipse来处理使用带有和没有BOM的utf-8编码的文本文件?

Quite straight forward question. Is there a way to configure Eclipse to work with text files encoded with utf-8 with and without the BOM?

到目前为止,我已经使用eclipse与utf-8编码它可以工作,但是当我尝试编辑由包含BOM的另一个编辑器生成的文件时,Eclipse不会正确处理它,它在文件(BOM)的起始处显示一个不可见的字符。有没有办法让Eclipse用BOM了解utf-8编码的文件?

So far I've used eclipse with utf-8 encoding and it works, but when I try to edit a file generated by another editor that includes the BOM, Eclipse doesn't handle it properly, it 'shows an invisible character' at the begining of the file (the BOM). Is there a way to make Eclipse understand utf-8 encoded files with BOM?

推荐答案

bug 78455 (提供强制将BOM写入UTF-8文件的选项)和 bug 136854 对这样的选项不要留下太多的希望。

Both bug 78455 ("Provide an option to force writing a BOM to UTF-8 files") and bug 136854 don't leave much hope for such an option.


工作区中对编码的支持是基于Java 可用的。

对于任何给定的资源在工作空间中,可以获得一个可以与任何采用字符集字符串的Java API一起使用的字符集字符串。

示例是:

The support for encoding in the workspace is based on what is available from Java.
For any given resource in the workspace, it is possible to obtain a charset string that can be used with any Java APIs that take charset strings.
Examples are:


  • ' US-ASCII ',

  • ' UTF-8 ',

  • ' Cp1252 ',

  • ' UTF-16 '(Big Endian,BOM自动插入),

  • ' UTF-16BE '(Big Endian,BOM未自动插入),

  • ' UTF-16LE '(小端,BOM未自动插入)。

  • 'US-ASCII',
  • 'UTF-8',
  • 'Cp1252',
  • 'UTF-16' (Big Endian, BOM inserted automatically),
  • 'UTF-16BE' (Big Endian, BOM not inserted automatically),
  • 'UTF-16LE' (Little Endian, BOM not inserted automatically).

对于Java编码,除了UTF-16编码,BOM不会插入(写入时)或丢弃(阅读时)免费

即使这对最终用户来说很困惑,这就是所有Java应用程序的工作原理。

如果应用程序想要支持使用BOM创建UTF-8文件以匹配用户的期望,他们需要自己提供这样的功能(既不是Java也不是资源模型将有帮助)。

Eclipse在检测BOM时提供一些改进,但不会产生或跳过它们。

For Java encodings, except for the 'UTF-16' encoding, BOMs are not inserted (when writing) or discarded (when reading) for free.
Even if this is puzzling to end users, this is how all Java applications work.
If applications want to support creating UTF-8 files with BOMs to match their users' expectations, they need to provide such capability on their own (as neither Java nor the Resources model will help with that).
Eclipse does provide some improvements towards detecting BOMs, but not with generating or skipping them.

这篇关于在Eclipse中使用utf-8文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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