Write I/O file to shared network drive using credentials

file-io, filesystems, java

Solution

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();

Thanks

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.

Problem

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){ } ``` Thank you.

Original source