1 HttpServletResponse response = ServletActionContext.getResponse(); 2 response.addHeader("Content-Disposition","attachment; filename="+ new String(name.getBytes(),"utf-8")); 3 response.setContentType("application/octet-stream"); 4 OutputStream out = response.getOutputStream(); 5 BufferedInputStream bin = new BufferedInputStream(new FileInputStream(path)); 6 byte[] buf = new byte[1024]; 7 int len = 0; 8 while ((len = bin.read(buf)) > 0) 9 out.write(buf, 0, len); 10 out.close(); 11 bin.close();
path参数为文件路径。
浙公网安备 33010602011771号