java程序读取远程机器共享文件

来源:互联网 发布:360浏览器网络收藏夹 编辑:程序博客网 时间:2024/06/04 18:43
package com.sgcc.jysf.file;

import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;

public class MainDemo {

  
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        
         try {
               SmbFile smbFile = new SmbFile("smb://用户名:密码@远程IP/共享文件/共享文件中需要读取的文本");
               int length = smbFile.getContentLength();
               byte buffer[] = new byte[length];
               SmbFileInputStream in = new SmbFileInputStream(smbFile);
            
               while ((in.read(buffer)) != -1) {

                System.out.write(buffer);
               }
               in.close();
              } catch (Exception e) {
               e.printStackTrace();
              }
    }
}


0 0
原创粉丝点击