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();
    		}
    	}
    
  • 相关阅读:
    python 中: lambda
    python 学习 argparse
    深度学习 ——style reconstruction
    简单linux命令1
    intptr_t 指针
    MySQL数据库基本命令-1
    交换机和路由器的区别
    UML图的使用
    操作系统总结链接
    操作系统总结
  • 原文地址:https://www.cnblogs.com/hefeisf/p/5039212.html
Copyright © 2011-2022 走看看