读取文件内容 @time: 2025-02-19 @param filepath: 文件路径 @param mode: 文件模式 @return: 文件内容
(self, filepath: str, mode: str = 'r')
| 496 | return False, '' |
| 497 | |
| 498 | def ReadFile(self, filepath: str, mode: str = 'r') -> str: |
| 499 | """读取文件内容 |
| 500 | @time: 2025-02-19 |
| 501 | @param filepath: 文件路径 |
| 502 | @param mode: 文件模式 |
| 503 | @return: <str> 文件内容 |
| 504 | """ |
| 505 | if not os.path.exists(filepath): |
| 506 | return '' |
| 507 | try: |
| 508 | with open(filepath, mode) as fp: |
| 509 | return fp.read() |
| 510 | except Exception: |
| 511 | try: |
| 512 | with open(filepath, mode, encoding="utf-8") as fp: |
| 513 | return fp.read() |
| 514 | except Exception as e: |
| 515 | # logging.error("Error reading file {}: {}".format(filepath, str(e))) |
| 516 | return '' |
| 517 | |
| 518 | def FileMd5(self, filepath: str) -> str: |
| 519 | """计算文件MD5 |