使用凭据将 I/O 文件写入共享网络驱动器 [英] Write I/O file to shared network drive using credentials

查看:20
本文介绍了使用凭据将 I/O 文件写入共享网络驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 .txt 文件放到共享网络驱动器上.该路径是需要凭据(登录名和密码)的网络驱动器上的映射.我可以使用 FileOutputStream 传递这些参数吗?

I want to drop a .txt file on a shared network drive. The path is a map on a networkdrive which requires credentials (login and password). Can i pass these parameters using FileOutputStream?

FileOutputStream fos;
DataOutputStream dos;

try {
    File file= new File(path + "/" + fileName + ".txt");
    fos = new FileOutputStream(file);
    dos=new DataOutputStream(fos);
    dos.writeChars(stringContent);
    dos.close();
    fos.close();
}
catch(IOException eio){
}

谢谢.

推荐答案

没有.使用 java CIFS 客户端库.您可以通过java连接远程Windows机器.示例 -

No. Use java CIFS Client library. you can connect remote windows machine through java. example -

String user = "user:password";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
String path = "smb://my_machine_name/D/MyDev/test.txt";
SmbFile sFile = new SmbFile(path, auth);
SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
sfos.write("Test".getBytes());
sfos.close();

谢谢

编辑:JCIFS 仅支持不安全的 SMB1 协议,并且多年来一直处于维护模式.使用 jcifs-ng 以获得 Windows 10 所需的 SMB2/SMB3 支持.

EDIT: JCIFS only supports the unsecure SMB1 protocol and has been in maintainance mode for some years. Use jcifs-ng for SMB2/SMB3 support which is required from Windows 10.

这篇关于使用凭据将 I/O 文件写入共享网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆