如何读取文件夹输入流中的文件
我有一个使用 3rd 方库创建的 Jar 文件。 当我打包 jar 文件时,我将几个 xml 文件包含在名为 data 的文件夹中。
data
- file1.xml
- file2.xml
- file3.xml
现在,我想读取 jar 文件内的文件夹并根据第 3 方库的文档 我可以获取类加载器并将文件夹作为输入流读取,如下所示。
ClassLoader clsLoader = myService.getClassLoader();
InputStream accountsStream = clsLoader.getResourceAsStream("data");
问题是,如何列出输入流中的所有文件并一一解析?
谢谢
编辑 添加信息:
How do I access resources that I put into my service or module archive file?
http://axis.apache.org/axis2/java/ core/faq.html#b1
抱歉,这个问题应该是特定于 Apache Axis 的,但如果它也是一个 Java 特定问题,我会有点困惑。
使用类加载器将输入流获取到文件夹后,如何列出该文件夹中的所有文件并一一读取它?
我的代码中的步骤将包括。
- 将输入流放入文件夹中
- 列出该输入流中的所有文件
- 一一读取
I have a Jar file that I have created using 3rd party library.
When I packaged the jar file, I am including several xml files inside it in a folder named data
data
- file1.xml
- file2.xml
- file3.xml
Now, I wanted to read the folder inside the jar file and as per the documentation of the 3rd party library
I could get the classloader and read the folder as inputstream like this.
ClassLoader clsLoader = myService.getClassLoader();
InputStream accountsStream = clsLoader.getResourceAsStream("data");
Question is, how can I list all the files from the inputstream and parse it one by one?
Thanks
EDIT
Added Info:
How do I access resources that I put into my service or module archive file?
http://axis.apache.org/axis2/java/core/faq.html#b1
Sorry, the question should have been specific to Apache Axis but I am confused a little bit if it is a Java specific question also.
After getting an inputstream to a folder using the classloader, how do I list all the files into that folder and read it one by one?
The steps in my code would inlcude.
- Get an inputstream into the folder
- List all files from that inputstream
- Read it one by one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(抱歉 - 忽略我的答案 - 这是一个更好的答案:)
如何列出 JAR 文件中的文件?
这是一个相当脆弱的解决方案,但是您可以只读取您自己的 jar 文件:
使它脆弱的原因是它取决于您的jarfile 具有特定的名称、不在另一个 jarfile 内等等。我确信有一种更优雅的方式......
(Sorry - ignore my answer - here's a better one:)
How do I list the files inside a JAR file?
This is a rather fragile solution, but you could just read your own jar file:
What makes it fragile is that it depends on your jarfile having a particular name, not being inside another jarfile, and so on. I'm sure there's a more elegant way...
data/listOfXML.txt
的列表。data/listOfXML.txt
at the same time.