gpt4 book ai didi

java - 查找 war 中目录中存在的所有文件的名称

转载 作者:行者123 更新时间:2023-12-02 05:08:48 25 4
gpt4 key购买 nike

我有一个具有以下结构的网络应用程序:

WEB-INF |-classes     |-templates         |-abc.properties         |- xyz.properties |-lib     |-internal.jar (all classes of our application)     |- other jars

这些被捆绑为一场 war

我想获取 WEB-INF/classes/templates 中存在的文件的名称另外我想根据文件名获取 WEB-INF/classes/templates 中文件的文件对象。注意:上述操作需要从internal.jar 中存在的类之一完成。基本上它们在类路径上

最佳答案

I want to get the file object of a file in WEB-INF/classes/templates based on name of the file

使用 java.io.File,你不能这样做。

使用 java.nio.file API,您可以:

final Path warpath = Paths.get("path to your war file here");

final URI uri = URI.create("jar:" + warpath.toUri());

try (
final FileSystem zipfs = FileSystems.newFileSystem(uri, Collections.emptyMap());
) {
final Path templates = zipfs.getPath("/WEB-INF/classes/templates");
// walk "templates" with Files.walkFileTree()
}

关于java - 查找 war 中目录中存在的所有文件的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27527870/

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