getResourceAsStream()返回null [英] getResourceAsStream() returns null
本文介绍了getResourceAsStream()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下问题
InputStream input = FileHandle.class.getResourceAsStream("/data/sounds/back.ogg");
返回null,但是
InputStream input = FileHandle.class.getResourceAsStream("/data/sounds/back.png");
返回InputStream,这两个文件也都在此文件夹中.有什么问题吗?
returns InputStream, also both files are in this folder. What can be wrong?
我正在使用libgdx-0.9.6
I'm using libgdx-0.9.6
推荐答案
如果路径以"/"开头,则Java会在文件系统的根目录中搜索文件.
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.
如果存在,则可以尝试另一种方法来获取其InputStream:
If it exists, you could try another way to get its InputStream:
InputStream is = new FileInputStream("/data/sounds/back.ogg");
这篇关于getResourceAsStream()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文