java下载文件夹_java如何通过共享目录下载文件夹(有子文件夹)到本地目录?...

这段代码演示了如何使用NtlmPasswordAuthentication进行身份验证,并从指定的SMB地址下载文件夹及其内容。然而,当前代码只能处理文件,无法处理子文件夹。要实现下载子文件夹的功能,需要递归遍历并下载所有子目录中的文件。
摘要由CSDN通过智能技术生成

有没有大神会操作的?

下面的代码只能下载文件夹下只是文件的,不能下载文件夹下包含子文件夹的文件public static void getShareFile(){

System.out.println("开始");

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("192.168.6.88","user1","[email protected]");

String url = "smb://192.168.6.88/tomcat/";

try{

SmbFile file = new SmbFile(url,auth);

if(file.exists()){

SmbFile[] files = file.listFiles();

for(SmbFile f : files){

String localDir = "F:\\vcc\\";

InputStream in = new BufferedInputStream(new SmbFileInputStream(f));

File localFile = new File(localDir + File.separator + f.getName());

OutputStream out = new BufferedOutputStream(new FileOutputStream(localFile));

System.out.println(f.getContentLength());

byte[] buffer = new byte[1024];

while(in.read(buffer) != -1){

out.write(buffer);

buffer = new byte[1024];

}

in.close();

out.close();

}

}else {

logger.info("共享目录不存在");

}

}catch(Exception e){

e.printStackTrace();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值