一个下载

String realPath = session.getServletContext().getRealPath("/template/authFile/authFiles.xlsx");
		response.reset();
		response.setCharacterEncoding("gb2312");
		OutputStream output = null;
		FileInputStream fis = null;
		try {
			request.setCharacterEncoding("utf-8");
			String fileName = "xxx清单.xlsx";
			String name = new String(fileName.getBytes("gb2312"), "ISO8859-1");
			response.setHeader( "Content-Disposition","attachment; filename=" + name);
			response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");  
			output = response.getOutputStream();
			fis = new FileInputStream(realPath);
			byte[] b = new byte[1024];
			int i = 0;
			while ((i = fis.read(b)) != -1) {
				output.write(b, 0, i);
			}
			output.flush();
			response.flushBuffer();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (fis != null) fis.close();
				if (output != null) output.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}

 

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