如何制作记事本以在没有BOM的情况下将文本保存为UTF-8? [英] How can I make Notepad to save text in UTF-8 without the BOM?
问题描述
我有一个 CSV 文件,该文件带有特殊重音,然后通过选择将其保存在记事本中UTF-8编码.当我使用Java读取文件时,它也会读取BOM表字符.
I have a CSV file with special accents and save 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 a built-in class in Java that eliminates the BOM characters that present at beginning, when reading the contents in a file?
推荐答案
-
使用 Notepad ++ -它免费且比记事本.使用 Encoding →可以在不使用BOM的情况下保存文本. 在没有BOM的情况下以UTF-8编码:
Use Notepad++ - it is free and much better than Notepad. It will help to save text without a BOM using Encoding → Encode in UTF-8 without BOM:
当我在Java中遇到此问题时,我没有找到任何库来解析这前三个字节(BOM).所以我的建议:
When I encountered this problem in Java, I didn't find any library to parse these first three bytes (BOM). So my advice:
- 使用
PushbackInputStream(in, 3)
. - 读取前三个字节
- 如果不是BOM( EF BB BF ),请将其推回
- 将流作为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
这篇关于如何制作记事本以在没有BOM的情况下将文本保存为UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!