[英]Java listFiles in directory in jar
Is there any way to use listFiles()
on a directory that's been packaged into a jar? 有没有办法在打包到jar中的目录上使用listFiles()
?
Let's say I have a directory in my resource directory with some text files: texts/text1.txt
and texts/text2.txt
. 假设我的资源目录中有一个目录,其中包含一些文本文件: texts/text1.txt
和texts/text2.txt
。
And within this Java program I have a class that needs to use listFiles()
to get a list of those files. 在此Java程序中,我有一个需要使用listFiles()
获取这些文件列表的类。 I'll get something like jar:file:/home/soupkitchen.jar/!text
. 我会得到像jar:file:/home/soupkitchen.jar/!text
。 I'd expect that to be a directory. 我希望这是一个目录。 Is there any way to be able to treat it as a java.io.File
directory containing files? 有什么方法可以将其视为包含文件的java.io.File
目录? Right now it seems to only be listed as neither a file nor directory. 现在,它似乎只被列出为文件和目录。
No. java.io.File can only be used to list real directories. 不可以。java.io.File仅可用于列出真实目录。
However, you can treat it as a java.nio.file.Path. 但是,您可以将其视为java.nio.file.Path。
Overall, you have three options: 总体而言,您有三个选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.