Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从资产读取文件引发FileNotFoundException_Android_Assets_Filenotfoundexception - Fatal编程技术网

Android 从资产读取文件引发FileNotFoundException

Android 从资产读取文件引发FileNotFoundException,android,assets,filenotfoundexception,Android,Assets,Filenotfoundexception,我正在使用以下代码: public void readLevel(int line){ AssetManager am = this.getAssets(); InputStream is = null; try { is = am.open("levelinfo.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.pri

我正在使用以下代码:

    public void readLevel(int line){
    AssetManager am = this.getAssets();
    InputStream is = null;
    try {
        is = am.open("levelinfo.txt");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Scanner scanner = new Scanner(is);
    scanner.useDelimiter(",");
    String skip;
    for(int i = 1; i < line; i++){
        skip = scanner.nextLine();
    }
    levelData = new ArrayList<Integer>();
    while(scanner.hasNextInt()){
        levelData.add(scanner.nextInt());
    }
}
public void readLevel(int行){
AssetManager am=this.getAssets();
InputStream=null;
试一试{
is=am.open(“levelinfo.txt”);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
扫描仪=新扫描仪(is);
scanner.useDelimiter(“,”);
串跳;
对于(int i=1;i
代码给出了FileNotFoundException。我见过一些类似的问题,但我不太确定如何解决它。该文件是“资源”文件夹中的文本文件。谢谢你的帮助

安迪

试着这样做:


谢谢你的回复。仍然遇到同样的问题,并且日志不在LogCat01-29 11:07:55.839:W/System.err(6791):java.io.FileNotFoundException:levelinfo.txt中。我将文件保存在“assets”中,它是主程序包的直接子文件夹。您的意思是说,您在assets文件夹中有一个文件夹,并且您的文件位于该文件夹中?像
资产/folder/file.txt
?是吗?不,这只是个很简单的错误。我读了一些其他的问题,并寻找一个更复杂的问题,而不是检查最简单的事情。阅读我上面的评论,感谢所有的帮助,欢迎。。。很高兴帮助你:)哎呀!错误,我保存了没有扩展名的.txt文件。
AssetManager assetManager = getResources().getAssets();
 InputStream inputStream = null;
try {
    inputStream = assetManager.open("levelinfo.txt");
        if ( inputStream != null)
            Log.d(TAG, "It worked!");
    } catch (IOException e) {
        e.printStackTrace();
    }