eclipse插件开发中如何使用InputStream读取目录
我正在开发一个eclipse插件,我需要遍历一个目录以及该目录的全部内容。我找到了将插件(bundleresource)中的文件读取为InputStream的方法。
InputStream stream = Activator.class.getResourceAsStream("/dir1/dir2/file.ext");
此方法仅适用于文件。我需要一种方法来读取目录、列出子目录和文件,例如 File.io。
谢谢。
I'm developing an eclipse plug-in and I need to traverse a directory and whole content of the directory. I found the method which reads a file in plug-in (bundleresource) as InputStream.
InputStream stream = Activator.class.getResourceAsStream("/dir1/dir2/file.ext");
this method works for files only. I need a way to read directories, list subdirectories and files like File.io.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想读取插件的资源目录吗?否则,您必须遍历一个目录并为每个文件打开一个流:
如果您还想遍历子目录,您应该将其包装到递归方法中,检查
file
是否是目录并在中调用递归方法这个案例。Do you want to read a resource directory of your plugin? Otherwise you have to traverse a directory and open one stream per file:
If you want to traverse subdirectories as well you should wrap this into a recursive method, check if
file
is a directory and call the recursive method in this case.