import os import codecs def convert_files_to_ansi(folder_path): for root, dirs, files in os.walk(folder_path): for file in files: if file.endswith(".java"): file_path = os.path.join(root, file) try: # 以UTF-8读取文件内容 with codecs.open(file_path, "r", "utf-8") as utf_file: content = utf_file.read() # 将内容以ANSI编码写回文件 with codecs.open(file_path, "w", "ansi") as ansi_file: ansi_file.write(content) print("已成功将文件 {} 转换为ANSI编码".format(file_path)) except Exception as e: print("转换文件 {} 出错:{}".format(file_path, str(e))) folder_path = "文件路径" convert_files_to_ansi(folder_path)
批量转换文件编码格式
最新推荐文章于 2024-06-03 13:31:43 发布