Java web下载文件功能的确很简单。如下代码片段 String fileName ="...."; response.setHeader("Content-disposition","attachment; filename="+fileName); //response.setContentType("application/ms-word"); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + fileName))); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048]; int bytesRead; while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff,0,bytesRead); } } catch(final IOException e) { System.out.println ( "IOException." + e ); } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); }String fileName ="... 你的当前访问异常,请进行认证后继续阅读剩余内容。 提交