首页 > Windows开发 > 详细

使用jcifs.smb.SmbFile读取Windows上共享目录的文件

时间:2015-02-28 14:17:56      阅读:757      评论:0      收藏:0      [点我收藏+]
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();
            }
        }
    }

 

使用jcifs.smb.SmbFile读取Windows上共享目录的文件

原文:http://www.cnblogs.com/yshyee/p/4305238.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!