标签:fileencoding 乱码 iconv
Windows系统中编辑的Java源码,在Linux下打开会出现中文乱码的情况。原因就是文件编码格式的问题,Windows下通常是GBK而Linux下是UTF-8。
在vim中用set fileencoding命令就可以看出编码格式,如下:
//linux下
fileencoding=utf-8
//windows下
fileencoding=latin1最简单的办法就是在windows下将文件另存为utf8格式。那么在linux下我们可以使用iconv工具将其转换格式。
$ iconv --help
Usage: iconv [OPTION...] [FILE...]
Convert encoding of given files from one encoding to another.
 Input/Output format specification:
  -f, --from-code=NAME       encoding of original text
  -t, --to-code=NAME         encoding for output
 Information:
  -l, --list                 list all known coded character sets
 Output control:
  -c                         omit invalid characters from output
  -o, --output=FILE          output file
  -s, --silent               suppress warnings
      --verbose              print progress information
  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version
$ iconv -f GBK -t UTF-8 test.java -o test2.java转换完毕,中文乱码就不见了。
标签:fileencoding 乱码 iconv
原文地址:http://blog.csdn.net/lincyang/article/details/44703351