使用jcifs.smb.SmbFile读取Windows上共享目录的文件
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream stream = null; BufferedInputStream buf = null; try { stream = response.getOutputStream(); response.setContentType("application/msword"); response.setHeader("Content-Disposition", "attachment;filename=" + new String("文档测试.doc".getBytes(), "iso8859-1")); String smbFile = "smb://用户名:密码@192.168.0.149/work/his/"; String fileName = "测试.doc"; SmbFile remoteFile = new SmbFile(smbFile+fileName); buf = new BufferedInputStream(new SmbFileInputStream(remoteFile)); byte buff[] = new byte[2048]; int readBytes = 0; while (-1 != (readBytes = buf.read(buff, 0, buff.length))) { stream.write(buff, 0, readBytes); } } catch (IOException ioe) { throw new ServletException(ioe.getMessage()); } finally { if (stream != null) { stream.close(); } if (buf != null) { buf.close(); } } }