@RequestMapping(value = "/test")
public void add(HttpServletRequest request, HttpServletResponse response){
//string 字符串 导出内容
String string = "。。。。。。。。。。";
//设置响应的内容类型
response.setContentType("text/plain");
//设置文件的名称和格式
response.addHeader("Content-Disposition","attachment;filename="
+ genAttachmentFileName( "文件名称", "JSON_FOR_UCC_")//设置名称格式,没有这个中文名称无法显示
+ ".txt");
BufferedOutputStream buff = null;
ServletOutputStream outStr = null;
try {
outStr = response.getOutputStream();
buff = new BufferedOutputStream(outStr);
buff.write(string.getBytes("UTF-8"));
buff.flush();
buff.close();
} catch (Exception e) {
//LOGGER.error("导出文件文件出错:{}",e);
} finally {try {
buff.close();
outStr.close();
} catch (Exception e) {
//LOGGER.error("关闭流对象出错 e:{}",e);
}
}
}
导出TXT demo
最新推荐文章于 2024-07-27 04:47:28 发布