`

文件下载

    博客分类:
  • Java
 
阅读更多
	private void download() throws IOException {
		HttpServletResponse response = getResponse();
		String fullPath = "e:\\Document\\intra-mart5Demo\\document_list.pdf";
		String fileName = fullPath.substring(fullPath.lastIndexOf("\\") + 1);
		FileInputStream file = new FileInputStream(fullPath);
		//set response
		response.setContentType("application/octet-stream;charset=utf-8");
		response.setHeader("Content-Disposition", "attachment;filename="+ fileName);
		//print
		ServletOutputStream out = response.getOutputStream();
		out.flush();
		byte buffer[] = new byte[1024];
		int size;
		
		while ((size = file.read(buffer)) != -1) {
			out.write(buffer, 0, size);
			out.flush();
		}
		
		file.close();
		out.close();
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics