`
Java_大猫
  • 浏览: 169846 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

文件下载

    博客分类:
  • J2SE
 
阅读更多
	public void publicDownFileCommon(HttpServletResponse response,
			HttpServletRequest request, String fullPath, String orgName)
			throws IOException {
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		try {
			request.setCharacterEncoding("UTF-8");
		//	String filePath = fullPath + File.separator + orgName;
//			response.setContentType("application/x-msdownload;");
//			response.setHeader("Content-disposition", "attachment; filename="
//					+ orgName);
			response.reset();   
			response.setContentType("application/octet-stream;charset=UTF-8");   
			response.addHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(orgName, "UTF-8"));  
			
			
			bis = new BufferedInputStream(new FileInputStream(fullPath));
			bos = new BufferedOutputStream(response.getOutputStream());
			byte[] buff = new byte[2048];
			int bytesRead;
			while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
				bos.write(buff, 0, bytesRead);
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		} finally {
			if (bis != null)
				bis.close();
			if (bos != null)
				bos.close();
		}
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics