本文介紹了使用 Apache FTPClient 檢索文件時(shí)如何保留修改日期?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在使用 org.apache.commons.net.ftp.FTPClient
從 ftp 服務(wù)器檢索文件.當(dāng)文件保存在我的機(jī)器上時(shí),我保留文件上最后修改的時(shí)間戳是至關(guān)重要的.有人對如何解決這個(gè)問題有建議嗎?
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 團(tuán)隊(duì)能夠?qū)崿F(xiàn)此功能.
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());
}
這篇關(guān)于使用 Apache FTPClient 檢索文件時(shí)如何保留修改日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!