zoukankan      html  css  js  c++  java
  • 使用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();
                }
            }
        }
  • 相关阅读:
    汇编学习笔记
    英语口语学习
    三层架构与MVC的区别
    “Razor” – a new view engine for ASP.NET
    代码生成
    最热门的敏捷书籍[转]
    推荐工具
    在IBM发现管理的真相[转]
    开源的通用帮助库
    单元测试
  • 原文地址:https://www.cnblogs.com/yshyee/p/4305238.html
Copyright © 2011-2022 走看看