gpt4 book ai didi

java - FTPClient.listFiles 没有以秒为单位返回时间

转载 作者:行者123 更新时间:2023-11-30 08:54:45 25 4
gpt4 key购买 nike

private static void getFTPFileProperties(FTPClient client,
String ftpLocation, String pattern) throws IOException {
FTPFile[] fileList=null;
fileList = client.listFiles();
for(int i=0;i<fileList.length;i++)
{
FTPFile file= fileList[0];
Calendar cal = file.getTimestamp();
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormater.format(cal.getTime()));
}
}

我已经编写了上述函数来检索文件详细信息。但不知何故,我正在检索没有文件秒部分的详细信息。我将 lastModifiedDate 检索为 2013-08-08 00:00:00,而它的实际 lastModifiedDate2013-08- 08 下午 12:53:27

最佳答案

FTPClient.listFiles使用古老的 LIST 命令。使用该命令,FTP 服务器返回类似于 Unix ls 命令的列表是很常见的。对于旧文件(超过一年),它仅显示精确到天的时间戳。

如今,您应该始终使用 FTPClient.mlistDir ,它使用现代 MLSD command始终以秒级精度检索时间戳。

public FTPFile[] mlistDir() throws IOException

当然,除非你连接到一个古老的 FTP 服务器,否则它不支持 MLSD 命令。

请注意,mlistDir 自 Apache Commons Net 3.0 起受支持。

关于java - FTPClient.listFiles 没有以秒为单位返回时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29300686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com