gpt4 book ai didi

java - 扫描 Web 容器文件夹中的文件

转载 作者:行者123 更新时间:2023-12-02 06:16:32 25 4
gpt4 key购买 nike

您好,我需要在 Web 文件夹中有一个名为策略的文件夹,该文件夹中将列出一个文件,我需要扫描该策略文件夹中的文件,因此我需要采取进一步的步骤。这是我的项目结构: project structure with policy folder and a file in the policy folder

我的问题是我需要扫描 Controller 中的策略文件夹并获取文件名。我怎样才能在 Java 中做到这一点。

最佳答案

File.listFiles()将为您提供文件列表。

File folder = new File(path); // path is your folder path.
File[] listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
//do your stuff
}
}

关于java - 扫描 Web 容器文件夹中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21399103/

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