绝望,上传文件失败。。遇到并解决java.lang.NullPointerException

Ethel ·
更新时间:2024-11-13
· 589 次阅读

解决报错:java.lang.NullPointerException

解决方法:将文件的编码方式改为utf-8即可!

截图:

修改成功后:

 

代码:

import os import json import re def json_to_html(i,cvenum): print('正在处理:'+cvenum) head = "漏洞对应信息摘要 " \ "

cvesummary for this cve

" tail = "
"#padding-left: 320px cvesummary_context = head + i + tail cvenum = str(cvenum) cvenum = cvenum.replace('-','')#去掉横杠 with open('D:/0html/'+cvenum+'.html', "w", encoding='utf-8') as json_file: json_file.write(cvesummary_context) json_file.close() print('D:/0html/'+i+'.html') def rewrite(): global num cve_inf_file = open('试试.json', "r", encoding='utf-8') cve_inf_context = json.load(cve_inf_file) for i in cve_inf_context: # print(i) json_to_html(i['cvesummary'],i['Cve_ID'])#原本数据写为HTML,并以CVE编号命名! ss = re.findall('\d+.\d+', str(i['Cve_ID'])) num += 1 print('\n处理第'+str(num)+'个数据。其CVE编号为:'+ss[0]+'对应的json文件! 共计:'+str(sum)+'个json文件\n') ss = str(ss[0]) ss = ss.replace('-', '') i['cvesummary'] = ""+"查看"+ss+"所对应信息摘要"+"" with open('cve_addprod.json', "w",encoding='utf-8') as json_file: json_str = json.dumps(cve_inf_context, indent=4, ensure_ascii=False) json_file.write(json_str) json_file.close() print('\n\n成功存储:D:/0test/cve_addprod.json. 一共'+str(num)+"条数据!") if __name__ == '__main__': global num num = 0 rewrite()

作者:dream_uping



java.lang lang JAVA 上传文件

需要 登录 后方可回复, 如果你还没有账号请 注册新账号