How to make Notepad to save text in UTF-8 without BOM?

时光怂恿深爱的人放手 提交于 2019-11-26 12:28:41
korifey
  1. Use Notepad++ - free and much better than Notepad. It will help to save text without BOM using Enconding > Encode in UTF-8 without BOM:

  2. When I encountered this problem in Java, I haven't found 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

Use Notepad++ instead. See my personal blog post on it. From within Notepad++, choose the "Encoding" menu, then "Encode in UTF-8 without BOM".

olaf atchmi

I just learned from this Stack Overflow post, as @martin-geisler points out, that you CAN save files without the BOM in Windows Notepad, by selecting ANSI as the encoding.

I'm assuming that for more advanced uses this won't work because the resulting file is probably not the end encoding wished, but actually ANSI; but I tested and confirmed this works to save a very small .php script without BOM using only Notepad.

I learned the long, hard way that Windows' Notepad is not a true editor, although I'd like to point out for others that, despite this, it is misleadingly called up when you type "editor" on newer Windows machines, at least on one of mine.

I am currently using Emacs and other editors to solve this problem.

The answer is: Not at all. Notepad can't do that.

In Java you can just skip the first byte in your InputStream and be done.

Jeow Li Huan

You might want to try out Notepad2 or Notepad++. Those Notepad replacements have the option for you to choose whether to output BOM.

As for a Java solution, as far as I know, Java does not understand the standard UTF-8. I googled and found Java's UTF-8 and Unicode writing is broken - Use this fix that might be the solution.

Thomas

We're using the utility BOMStripperInputStream.java to strip the BOM from our input if present.

Notepad on Windows 10 1903 and later versions supoprt saving to UTF-8 without BOM. In fact, UTF-8 is the default file format now.

Reference: https://www.bleepingcomputer.com/news/microsoft/windows-10-notepad-is-getting-better-utf-8-encoding-support/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!