如何使记事本保存文本在UTF-8没有BOM? [英] How to make Notepad to save text in UTF-8 without BOM?
问题描述
我有一个具有特殊口音的 CSV 文件,并通过选择UTF-8编码将其保存在记事本中。当我使用Java读取文件时,它也读取BOM字符。
I have a CSV file with special accents and saving it in Notepad by selecting UTF-8 encoding. When I read the file using Java, it reads the BOM characters too.
因此,我想以UTF-8格式保存此文件,而不是最初在记事本中添加BOM。
So I want to save this file in UTF-8 format without appending a BOM initially in Notepad.
否则,在读取文件中的内容时,Java中是否有任何内置类消除了开头出现的BOM字符?
Otherwise is there any built-in class in Java that eliminates the BOM characters that present at beginning, when reading the contents in a file?
推荐答案
-
使用记事本++ - 免费,比记事本好多了。在没有BOM的情况下,使用 Enconding > 在UTF-8中编码而不使用BOM ,将有助于保存文本:
Use Notepad++ - free and much better than Notepad. It will help to save text without BOM using Enconding > Encode in UTF-8 without BOM:
当我在Java中遇到这个问题,我没有找到任何库来解析这三个字节(BOM)。所以我的建议是:
When I encountered this problem in Java, I haven't found any library to parse these first three bytes (BOM). So my advice:
- 使用
PushbackInputStream(in,3)
。 >
- 读取前三个字节
- 如果不是BOM( EF BB BF $ b
- 将流处理为UTF-8
- Use
PushbackInputStream(in, 3)
. - Read the first three bytes
- If it's not BOM (EF BB BF), push them back
- Process the stream as UTF-8
这篇关于如何使记事本保存文本在UTF-8没有BOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!