Change file encoding without losing information in the intellectual idea

Is it possible to change the encoding of a file from UTF-8 to windows1251 without losing Cyrillic information. Because when I explicitly change the encoding, do all Cyrillic characters become unreadable?

+6
source share
2 answers

UPDATE : new versions of the IDE can convert encodings:


The problem is that IntelliJ IDEA does not actually convert the encoding of your file from UTF-8 to windows-1251 , which happens when you tell IntelliJ IDEA to treat the UTF-8 file as encoded in windows-1251 , so you will see garbage in the editor. The actual file on disk remains in UTF-8 .

To perform the conversion, you need to use an external tool, for example iconv :

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

Newer versions of IntelliJ will ask if you want to "reload" or "convert" the file to the new encoding.

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

Tested with version 12.1.3

+4
source

Source: https://habr.com/ru/post/899668/


All Articles