我正在使用共享文件。我正在使用jcifs.jar库获取共享文件列表。
NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication(host, username, password);
SmbFile rootFile = new SmbFile(fullPath, authentication);
SmbFile[] listFiles = root.listFiles();
for (int i = 0, i< listFiles.length; i++) {
SmbFile sf = listFiles[i];
//I need to get last accessed date of each sf file.
}
如何获取每个“ sf”文件的最后访问日期?
编辑
对于java.io.File,我们可以这样获取上次访问日期:
Path path = file.toPath();
BasicFileAttributes fattr = Files.readAttributes(path, BasicFileAttributes.class);
LocalDate fileLastAccessed = Instant.ofEpochMilli(fattr.lastAccessTime().toMillis())
.atZone(ZoneId.systemDefault()).toLocalDate();
答案 0 :(得分:0)
没有嵌入式方法可以检查上次访问。最近的修改方法是最后修改:
getDate
public long getDate()
This URLConnection method just returns the result of lastModified.
Overrides:
getDate in class java.net.URLConnection
Returns:
the last modified data as milliseconds since Jan 1, 1970