如果代码文件里即有GBK又有UTF-8编码,且又没有enca的情况下,可以用shell,iconv,php稍微搞一下:
1)用PHP写一个测试文件编码的小程序
vi ~/bin/detect_encoding
#!/usr/bin/php -n
<?php$file=fopen(‘php://stdin’,'r’);
$s = ”;
while (!feof($file)) {
$buffer = fgets($file,4096);
$s.=$buffer;
}
fclose($file);
echo mb_detect_encoding($s,”ASCII,UTF-8,GBK”);
2 ) 找出所有GBK编码的文件:
for f in `find . -name “*.java”`; do ~/bin/detect_encoding < $f; echo ” $f”; done | grep CP936 | cut -b 6- > tmp_list
3)用iconv批量转
for i in `cat tmp_list`; do iconv -f GBK -t UTF-8 $i > tmp; mv tmp $i; done
–搞定–
My name is Hugo Zhu.



