读取资源最终为null

时间:2013-03-10 09:29:18

标签: java null inputstream

我有以下代码

System.out.println("Path::: "+path);
InputStream resource = this.getClass().getResourceAsStream(path);

现在路径是: SRC /资源/ FF / 1-Battle.mp3

这是我的文件夹结构:

src 
 |- resources
 |    |- FF
 |    |   |- 1-Battle.mp3
 |- folder
 |    |- prog.java   <- this is the place where the code is run

问题是资源(输入流)结束为空

这需要从一个jar文件工作,所以我需要它来自jar文件root directoy而不是硬盘目录,因此我无法创建一个文件,因为在jar文件中,文件在java下是不可分类的。 io.File

2 个答案:

答案 0 :(得分:2)

为什么不能使用FileInputStream阅读它?这样的事情: -

InputStream fileStream = new FileInputStream(new File(path));

并确保路径是正确的相对URL。

答案 1 :(得分:0)

您是否尝试使用执行程序的相对路径?喜欢'../../ resources / FF / 1-Battle.mp3“?

相关问题