从SVN上下载的代码,有些是使用eclipse的同事上传的,在IDEA里编译时报错,查了下是utf8的bom头信息引起的。通过下面的python脚本批量去除就好。
import os, time
if __name__ == '__main__':
start = time.time()
directory = "D:/IdeaProjects/MES91/src"
for cdir, subdirs, files in os.walk(directory):
for file in files:
if file.endswith(".java"):
print(file)
bom_file = os.path.join(cdir, file)
s = open(bom_file, mode='r', encoding='utf-8-sig').read()
open(bom_file, mode='w', encoding='utf-8').write(s)
print("cost time: %.3fs" % (time.time() - start))