Modify remote files

0

Good, I am accessing files that I have in a shared folder in a network drive, and not to mount the disk in each pc I create an object of the File class in the following way:

File f = new File("file://190.10.10.240/Cedulas/").

I have access to the files, when I open the relevant code it opens and I can work with them, but when I want to rename the file it does not. Previously he had them like this:

File f = new File("S:/190.10.10.240/Cedulas/");

and the rename I did it without problem

f.renameTo(f2);

Any idea why?

    
asked by Carlos 16.02.2017 в 12:29
source

1 answer

1

good!

If the computer that has the shared folder is windows, it seems to me that it can be because when you map the directory as a network unit, it uses the user's credentials to access them keeping them "open". While accessing directly to the file without Network mapping you will need to pass your credentials in some way, you can try this:

String credenciales = "user:password";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(credenciales);
String f1= "smb://190.10.10.240/Cedulas/test.txt";
String f2= "smb://190.10.10.240/Cedulas/testRename.txt";
SmbFile smbFile = new SmbFile(f1, auth);
SmbFile smbFileRename = new SmbFile(f2, auth);
smbFile.rename(smbFileRename);
    
answered by 16.02.2017 / 13:06
source