getResourceAsStream() returns null

梦想的初衷 提交于 2019-12-12 12:29:17

问题


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


回答1:


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

If it is in your root folder, first of all, check if file exists:

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

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

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

InputStream is = new FileInputStream("/data/sounds/back.ogg");


来源:https://stackoverflow.com/questions/12262062/getresourceasstream-returns-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!