zoukankan      html  css  js  c++  java
  • 文件下载

    /**
    	 * 下载文件
    	 * 
    	 * @param basePath
    	 * @throws IOException
    	 */
    	private void downLoadFile(String basePath) throws IOException {
    		HttpServletResponse response = ServletActionContext.getResponse();
    		File zipFile = new File(basePath + ".zip");
    		try {
    			// 以流的形式下载文件。
    			InputStream fis = new BufferedInputStream(new FileInputStream(
    					zipFile.getPath()));
    			byte[] buffer = new byte[fis.available()];
    			fis.read(buffer);
    			fis.close();
    			// 清空response
    			response.reset();
    			// 设置response的Header
    			response.addHeader("Content-Disposition", "attachment;filename="
    					+ new String(zipFile.getName().getBytes("utf-8")));
    			response.addHeader("Content-Length", "" + zipFile.length());
    			OutputStream toClient = new BufferedOutputStream(
    					response.getOutputStream());
    			response.setContentType("application/octet-stream");
    			toClient.write(buffer);
    			toClient.flush();
    			toClient.close();
    		} catch (Exception e) {
    			PrintWriter out = response.getWriter();
    			out.print("<script>alert('down file err');</script>");
    			out.close();
    		}
    	}
    
  • 相关阅读:
    Another mysql daemon already running with the same unix socket
    cloud maintenance of OpenNebula
    内核分析阅读笔记
    eucalyptus,openNebula云构建漫谈
    quotation
    Adress
    cos
    COS回应7大质疑
    linux内核地址mapping
    开源 免费 java CMS
  • 原文地址:https://www.cnblogs.com/hefeisf/p/5039212.html
Copyright © 2011-2022 走看看