如何使用Apache FTPClient检索文件时保留修改日期? [英] How to preserve date modified when retrieving file using Apache FTPClient?
本文介绍了如何使用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?
推荐答案
这就是我解决问题的方法:
This is how I solved it:
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.
您可以如何使用它:
This is how you can use it:
List<FTPFile> ftpFiles = Arrays.asList(client.listFiles());
for(FTPFile file : ftpFiles) {
retrieveFile("/tmp", file.getName(), file.getTimestamp().getTime());
}
这篇关于如何使用Apache FTPClient检索文件时保留修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文