gpt4 book ai didi

java - 如何获取提到的特定位置中的文件名

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

谁能告诉我如何获取特定位置的文件名

E:/abc_RESPONSE/Response_

我试着用了

java.io.File.getName()

方法返回路径名的名称序列的最后一个名称,即返回此抽象路径名所表示的文件或目录的名称。但是我需要那个特定位置的所有文件名。

String name = (String)(new File("E:/abc_RESPONSE/Response_").getName());

我正在使用上面的代码,请帮助实现这个。

最佳答案

试试这个..

 public void listFiles(String directoryName){

File directory = new File(directoryName);

//get all the files from a directory

File[] fList = directory.listFiles();

for (File file : fList){

if (file.isFile()){

System.out.println(file.getName());

}

}

}

关于java - 如何获取提到的特定位置中的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28314032/

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