本文介紹了使用 Apache FTPClient 檢索文件時如何保留修改日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 org.apache.commons.net.ftp.FTPClient
從 ftp 服務器檢索文件.當文件保存在我的機器上時,我保留文件上最后修改的時間戳是至關重要的.有人對如何解決這個問題有建議嗎?
I am using org.apache.commons.net.ftp.FTPClient
for retrieving files from a ftp server. It is crucial that I preserve the last modified timestamp on the file when its saved on my machine. Do anyone have a suggestion for how to solve this?
推薦答案
我是這樣解決的:
public boolean retrieveFile(String path, String filename, long lastModified) throws IOException {
File localFile = new File(path + "/" + filename);
OutputStream outputStream = new FileOutputStream(localFile);
boolean success = client.retrieveFile(filename, outputStream);
outputStream.close();
localFile.setLastModified(lastModified);
return success;
}
我希望 Apache 團隊能夠實現此功能.
I wish the Apache-team would implement this feature.
你可以這樣使用它:
List<FTPFile> ftpFiles = Arrays.asList(client.listFiles());
for(FTPFile file : ftpFiles) {
retrieveFile("/tmp", file.getName(), file.getTimestamp().getTime());
}
這篇關于使用 Apache FTPClient 檢索文件時如何保留修改日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!