文件下载

	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();
		}
	}

你可能感兴趣的:(文件下载)