@RequestMapping("download")
public void download(HttpServletResponse res) throws IOException {
OutputStream os = res.getOutputStream();
try {
res.reset();
res.setHeader("Content-Disposition", "attachment; filename=dict.txt");
res.setContentType("application/octet-stream; charset=utf-8");
os.write(FileUtils.readFileToByteArray(getDictionaryFile()));
os.flush();
} finally {
if (os != null) {
os.close();
}
}
}
@RequestMapping(value = "/conf/confdwn.json", method = RequestMethod.GET) public void downloadConf(HttpServletResponse response, Integer id) throws IOException { long start = System.currentTimeMillis(); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=" + conf.getName() + ".json"); response.setContentType("application/octet-stream; charset=utf-8"); response.getWriter().write(conf.getValue()); response.flushBuffer(); long end = System.currentTimeMillis(); System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<used time:" + (end - start)); }
http://www.iteye.com/topic/1125784