gpt4 book ai didi

eclipse - 在 Eclipse 中使用 utf-8 文件

转载 作者:行者123 更新时间:2023-12-02 11:38:46 25 4
gpt4 key购买 nike

非常直接的问题。有没有办法配置 Eclipse 来处理使用 utf-8 编码(带或不带 BOM)的文本文件?

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

最佳答案

两者bug 78455 (“提供一个选项来强制将 BOM 写入 UTF-8 文件”)和 bug 136854不要对这样的选择抱太大希望。

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 inserted automatically),
  • 'UTF-16BE' (Big Endian, BOM not inserted automatically),
  • 'UTF-16LE' (Little Endian, BOM not inserted automatically).

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 - 在 Eclipse 中使用 utf-8 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com