Table of content:
- Garbled problem
- Use Gedit to select the correct character encoding to open the file
- File transcoding
- Summarize
§ garbled
Fedora is installed by default with the UTF-8 character encoding, which has the advantage of internationalization (and many are compatible with utf-8), but there are compatibility issues. Like what:
The Chinese code under Windows is not UTF-8 encoded, because the policy requires that the software sold in China should use GB code (ie GBK, GB2312, GB18030 (latest))
So Chinese windows is encoded with GB18030, which leads to a small problem. The file that opens Windows under Linux is garbled,
Open a GB18030 encoded file with Gedit (double-click to open)
Why, because Gedit encode (decode) with GB18030 encoded text in decoding Utf-8, just like explaining a piece of French in English, translating a bunch of meaningless sentences.
§ Open with correct character encoding (character encodings)
the way to solve garbled characters is very simple, gedit itself supports a lot of character encoding,
1. Open the file with Gedit Open,
Select another file (other documents ...)
2.
(Select the correct character encoding at the character encoding in the lower left corner)
The file then opens normally:
(Please ignore the text content, just happens to be this file, not to advertise to the website ...)
In addition, if you open a file by using the command line, you can open it by gedit--encoding the appropriate encoding .
§ transcoding
Open a file with Gedit
(This file is encoded with gb2312)
Save as SaveAs at this point select Utf-16 in the lower left corner of the code, click Save
At this time the new file is utf-16 format, the terminal with the file command can see the new encoding
$ file New text saved with utf-16. txt with UTF-16 new text saved. Txt:little-endian utf-Unicode text, with CRLF, CR line te Rminators
There are other tools for transcoding, converting GB18030 to utf-8, such as Iconv
Usage: iconv [options] [-f from-encoding] [-t to-encoding] [inputfile] ...
$ file Win_gb2312.txt Win_gb2312.txt:ISO-8859-F gb2312-t utf-8 win_ Gb2312.txt -o utf_encoding.txt # (-o option specifies output file) $ file utf_encoding.txt Utf_encoding.txt:UTF-8 Unicode text, with CRLF line terminators
§ Summary
There are some drawbacks to these methods: you should know in advance what the original encoding of the file is, or you will have to try it one at a time.
How to view the encoding of a file, can be viewed with the files command, but the file command is not reliable, a gb2312 encoded Files command is judged as ISO-8859 ...
So it is not enough "smart" ah. These softwares ...
Windows Chinese file garbled problem under Linux