簡體   English   中英

Smbfile獲取Java中的上次訪問日期

[英]Smbfile get last accessed date in java

我正在使用共享文件。 我正在使用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();

沒有嵌入式方法可以檢查上次訪問。 最近的修改方法是:

 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM