1

我有一个试图读取文件的小程序。它引发了一个异常,但我将它传递给了正确的路径,所以我不确定我哪里出错了。如果您想知道,我正在使用它来读取数字并使用这些数字来更改多维数组。继承人的代码:

public class Save {
    public void loadSave(File loadPath) {
        try {
            Scanner loadScanner = new Scanner(loadPath);

            while(loadScanner.hasNext()){
                for(int y = 0; y < Screen.room.block.length;y++){
                    for(int x = 0; x < Screen.room.block[0].length;x++){
                        Screen.room.block[y][x].groundID = loadScanner.nextInt();
                        System.out.println(loadScanner.nextInt());
                    }   
                }
                for(int y = 0; y < Screen.room.block.length;y++){
                    for(int x = 0; x < Screen.room.block[0].length;x++){
                        Screen.room.block[y][x].airID = loadScanner.nextInt();
                    }   
                }
            }
            loadScanner.close();
        } catch (Exception e) { e.printStackTrace();}
    }
}

我如何访问它:

    save.loadSave(new File(frame.getClass().getResource("mission1.tdm").toString()));

好的,我使用了上面编辑过的代码,它仍然说它找不到文件,即使错误吐出了它所在的确切路径。

4

0 回答 0