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

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:49   2600   0
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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP