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();
    		}
    	}
    
  • 相关阅读:
    JQuery使用总结
    JS应用总结
    Base64数据转成Excel,并处理Excel的格式
    HTTP压缩
    谷歌开发工具解析
    .Net LIst排重
    MySql日志系统
    .Net生成PDF流
    Mysql MVCC
    JAVA期末综合课程设计
  • 原文地址:https://www.cnblogs.com/hefeisf/p/5039212.html
Copyright © 2011-2022 走看看