Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change file encoding without information losses in intellij idea

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?

like image 644
Sergey Avatar asked Oct 20 '11 04:10

Sergey


2 Answers

UPDATE: new IDE versions can convert encodings:

  • http://blogs.jetbrains.com/idea/2013/03/use-the-utf-8-luke-file-encodings-in-intellij-idea/

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>
like image 167
CrazyCoder Avatar answered Sep 28 '22 00:09

CrazyCoder


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

like image 33
Mike Rylander Avatar answered Sep 28 '22 00:09

Mike Rylander