本文介绍了如何让记事本在没有 BOM 的情况下以 UTF-8 格式保存文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有特殊口音的

  • 当我在Java中遇到这个问题时,我没有找到任何库来解析这前三个字节(BOM).所以我的建议:

    • 使用PushbackInputStream(in, 3).
    • 读取前三个字节
    • 如果不是 BOM (EF BB BF),则将它们推回
    • 将流处理为 UTF-8
  • 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.

    So I want to save this file in UTF-8 format without appending a BOM initially in Notepad.

    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?

    解决方案
    1. Use Notepad++ - it is free and much better than Notepad. It will help to save text without a BOM using EncodingEncode in UTF-8 without BOM:

      Notepad++ v6 and olders:

      Notepad++ v7+:

    2. When I encountered this problem in Java, I didn't find any library to parse these first three bytes (BOM). So my advice:

      • 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 格式保存文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-05 21:24