GetResourceAsStream () returns null

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 an InputStream, both files are in this folder. What could be wrong?

I am using libgdx-0.9.6

+2
java libgdx
Sep 04
source share
1 answer

If your path starts with "/", java will look for your file in the root of your file system.

If this is in the root folder, first check if the file exists:

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

If it does not exist or you do not have permissions, you have the answer.

If it exists, you can try another way to get its InputStream:

 InputStream is = new FileInputStream("/data/sounds/back.ogg"); 
+1
Sep 04 '12 at 11:13
source share



All Articles