我想让第二次写入时在原文件的末尾开始写如何修改代码:def apk_add_filefile_path apk_file_path apk_file_name try if public_functionis_file_existfile_path and public_functionis_file_existapk_file_path zf = zip
你可以修改代码,将文件的写入模式从"a"更改为"w",这样就可以在原文件的末尾开始写入了。修改后的代码如下:
def apk_add_file(file_path, apk_file_path, apk_file_name):
try:
if public_function.is_file_exist(file_path) and public_function.is_file_exist(apk_file_path):
zf = zipfile.ZipFile(apk_file_path, "w", zipfile.ZIP_DEFLATED)
name_list = zf.namelist()
if apk_file_name in name_list:
zf.close()
apk_delete_file(apk_file_path, apk_file_name)
zf = zipfile.ZipFile(apk_file_path, "w", zipfile.ZIP_DEFLATED)
zf.write(file_path, apk_file_name)
zf.close()
else:
zf.write(file_path, apk_file_name)
zf.close()
return True
else:
logging.error(
"the " + file_path + " or " + apk_file_path + " does not exist!")
return False
except IOError:
return False
请注意,在将写入模式更改为"w"后,将会覆盖原文件的内容,因此在写入之前,你可能需要备份原文件
原文地址: https://www.cveoy.top/t/topic/ig20 著作权归作者所有。请勿转载和采集!