gpt4 book ai didi

java - 避免 FTP 中的 "."和 ".."目录

转载 作者:行者123 更新时间:2023-12-02 07:34:19 25 4
gpt4 key购买 nike

当我使用 Apache commons API 检索 FTP 文件时,我收到“.”所有目录(包括子目录)中的“..”目录。如何避免这两个目录?有人可以建议我吗?

我的代码是:

client.changeWorkingDirectory("/");
String[] names = client.listNames();
for (String name : names) {
System.out.println("File Name = " + name);
}
FTPFile[] ftpFiles = client.listFiles(); // Want to eliminate "." and ".." files

output:
File Name = .
File Name = ..
File Name = .ftpquota
File Name = file1
File Name = file2

最佳答案

您只需将它们过滤掉(它们分别代表当前目录,FTP 将自动向您报告这些内容)。

也许可以使用 Apache Commons Collections filter机制?

关于java - 避免 FTP 中的 "."和 ".."目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12475882/

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