How to remove BOM in Intellij Idea

15,719

Solution 1

There is no such action to remove BOM from UTF-8 files in IntelliJ IDEA. There was a bug that BOM is removed, but it was fixed a long time ago.

When you remove BOM externally, make sure the file is synchronized with editor, try File | Synchronize.

If IntelliJ IDEA still thinks that this file has BOM, please file an issue with the steps to reproduce.

Solution 2

Tested on PHPStorm 8:

Right click on a file in the project tree, click on "Remove BOM"

(Not sure if it exists on the base platform, comments will be helpful)

Solution 3

Intellij Idea has an option, File->Remove Bom, but it looks doesn't work very well, I got "This file has mandatory Bom" error

The following tips work for me

1) create new empty file (for example: temp123.java)

2) make sure that code-page/encoding for that file is UTF-8

3) copy whole content from original to newly created file (select all, copy, go > to another tab, paste) and save

I referenced link below, can be combined with Intellij Idea File->File Encoding-> Reload/Convert to UTF-8

IDEs Support: Remove BOM from file - how ?

Share:
15,719
tsds
Author by

tsds

More often I'm writing code in: TypeScript, Dart, ES6 Python Rust Java, Scala, Kotlin

Updated on June 16, 2022

Comments

  • tsds
    tsds almost 2 years

    I'd like to remove Bite Order Masks from my
    UTF-8 files in Intellij IDEA, how can I do this?

    The problem is that if I'm trying to do it via other editors (e.g. Akelpad),
    when I modify the file later in IDEA it somehow remembers that BOM
    was present and adds it to my file again (((

  • rsenna
    rsenna almost 11 years
    +1 for the File | Synchronize hint. IntelliJ is not able to aptly recognize external BOM changes, but this helps. Still, any further change to the same file, inside IntelliJ, will bring the BOM back... :-/ (IntelliJ CE 12). AFAIK the only way of making this REALLY annoying behavior go away is 1) closing IntelliJ, 2) remove the *&¨*&#ing BOM and 3) reopening it.