4

I have the following problem

InputStream input = FileHandle.class.getResourceAsStream("/data/sounds/back.ogg");

returns null, but

InputStream input = FileHandle.class.getResourceAsStream("/data/sounds/back.png");

returns InputStream, also both files are in this folder. What can be wrong?

I'm using libgdx-0.9.6

4

1 回答 1

2

如果您的路径以“/”开头,java 将在文件系统的根目录中搜索您的文件。

如果它在您的根文件夹中,首先检查文件是否存在:

ls -l /data/sounds/ | grep "back.ogg"

如果它不存在或您没有权限,那么您有答案。

如果它存在,你可以尝试另一种方法来获取它的 InputStream:

InputStream is = new FileInputStream("/data/sounds/back.ogg");
于 2012-09-04T11:13:12.947 回答