Change file encoding without information losses in intellij idea

11,058

Solution 1

UPDATE: new IDE versions can convert encodings:


The problem is that IntelliJ IDEA doesn't actually convert your file encoding from UTF-8 to windows-1251, what happens is that you tell IntelliJ IDEA to treat UTF-8 file as being encoded in windows-1251, so you will see garbage in the editor. The actual file on disk remains in UTF-8.

You have to use some external tool to perform the conversion, such as iconv:

iconv.exe -f utf-8 -t windows-1251 <input file> > <output file>

Solution 2

Newer versions of IntelliJ will ask if you would like to "Reload" or "Convert" the file to the new encoding.

I had a file that was displayed using UTF-8 but was actually written in x-macRoman. I selected x-macRoman and chose "Reload" so that the encoding would be used to interpret the file, I then chose UTF-8 and selected "Convert". Now my file is properly encoded as UTF-8

Tested With: version 12.1.3

Share:
11,058
Sergey
Author by

Sergey

I'm a student.

Updated on June 18, 2022

Comments

  • Sergey
    Sergey almost 2 years

    Is it possible to change file's encoding from UTF-8 to windows1251 without cyrillic information lost. Because when I explicitely change the encoding, all cyrillic symbols become unreadable?