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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With