码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-02-28 14:18:36      阅读:291      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!