java创建文件写入内容,并实现下载该文件
public void getText(){
response.setHeader("Content-Disposition", "attachment;filename="
+ new String(("omd_services.sql").getBytes(), "iso-8859-1"));
try {
OutputStreamWriter write = new OutputStreamWriter(response.getOutputStream(), "utf-8");
BufferedWriter writer = new BufferedWriter(write);
StringBuilder sql = new StringBuilder();
sql.append("HELLO WORLD!");
writer.write(sql + "\r\n");
writer.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
"utf-8":防止写入文件乱码
"\r\n":追加数据
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步