I have the following code to check the last modification on a file saved on network drive.
private long determineLastEdit(ILoaderData file) {
String localDir = "c:\\Software\\log\\";
String localPDF = "empty28.pdf";
String originDir = "smb:\\ProdName\\ShareName\\Temp\\username\\path\\to\\folder\\";
//My company remote storage
File localFile = new File(originDir + localPDF)
//this does not work
//File localFile = new File(localDir + localPDF)
//this works as expected
Date currentTime = new Date();
long timeCurrent = currentTime.getTime();
long timeFile = localFile.lastModified();
//this returns 0 on remote, correct time on local
boolean fileEx = localFile.isFile(); //returns false on remote, true on local
boolean fileTp = localFile.isAbsolute(); //returns false on remote, true on local
long difference = Math.abs(timeCurrent - timeFile);
return difference;
}
The parameter given to constructor of a file is following:
smb:\\\ProdName\\\ShareName\\\Temp\\\username\\\path\\\to\\\folder\\\empty28.pdf
However, the lastModified() method returns 0 for some reason, what am I doing wrong? The file has no lock of any kind, it is regular (altough empty PDF).
EDIT1: I tested the method on local file, the path was:
c:\\\Software\\\log\\\empty28.pdf
And the value returned was correct, my suspicion was that method was not allowed to execute on a given file since it's on network drive. However, this check happens on one thread that is already authorized. No clue where the error is.
EDIT2: I updated code to provide better examples. Right now, it seems the problem is with reading file from network drive
EDIT3 I Tried using different method. Imported:
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
and added code:
Path path = Paths.get(localDir + localPDF);
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
with same result, again, local drive works and remote is not working.
boolean fileEx = localFile.isFile(); //returns false
? That "returns false" seems important...