如何制作记事本以在没有BOM的情况下将文本保存为UTF-8? [英] How can I make Notepad to save text in UTF-8 without the BOM?

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

问题描述

我有一个 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?

推荐答案

  1. 使用 Notepad ++ -它免费且比记事本.使用 Encoding →可以在不使用BOM的情况下保存文本. 在没有BOM的情况下以UTF-8编码:

  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:

当我在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屋!

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