java项目批量GBK文件转为UTF-8文件-脚本

批量GBK文件转为UTF-8 shell 脚本

basepath=`pwd`
touch $basepath/bakfile.list

for JAVA_FILE in $(find ./ -name "*.java")
    do
        if [ "$(file $JAVA_FILE | grep -v UTF-8)" != "" ] ;then
            echo convert $JAVA_FILE
            iconv -f GBK -t UTF-8 $JAVA_FILE > ${JAVA_FILE}.bak
            echo "${JAVA_FILE}" >> $basepath/bakfile.list
        fi
done

查看编码是否可用,然后全局替换

 for f in `cat $basepath/bakfile.list` ;do echo $f;  mv "$f.bak" $f ; done
posted @ 2020-08-16 22:02  bendandan  阅读(276)  评论(0编辑  收藏  举报