更新文本编码错误

This commit is contained in:
997146918 2025-08-08 19:41:16 +08:00
parent 249bfbcb9f
commit 54751fe89e

View File

@ -86,5 +86,12 @@ class ReadFiles:
@classmethod @classmethod
def read_text(cls, file_path: str): def read_text(cls, file_path: str):
# 读取文本文件 # 读取文本文件
with open(file_path, 'r', encoding='utf-8') as file: encodings = ['gb18030', 'gbk', 'gb2312', 'big5', 'iso-8859-5', 'cp1252', 'latin1']
return file.read() for enc in encodings:
try:
with open(file_path, 'r', encoding=enc) as f:
return f.read()
except :
continue
# with open(file_path, 'r', encoding='utf-8') as file:
# return file.read()