尝试catch无法读取文件

时间:2014-02-07 23:32:29

标签: java file find try-catch

我正在运行此方法但由于某种原因我无法找到数据记录,它继续捕获。有人可以告诉我在哪里搞砸了。我将data.txt文件放在与java文件相同的目录中。

public static Games[] gamesRecord(){
    Games[] game = new Games[50];
    try{
        Scanner dataFile = new Scanner(new File("data.txt"));        
        for(int i = 0; i > 50; i++){
            game[i].title = dataFile.next();
            game[i].releaseDate = dataFile.nextInt();
            game[i].redistributions = dataFile.nextInt();
            game[i].platformRelease = dataFile.next();
        }
    }catch(FileNotFoundException e){
        System.out.println("File data.txt was not found");
        System.out.println("or could not be opened.");
        System.exit(0);
    }
    return game;
}

1 个答案:

答案 0 :(得分:0)

通过放置文件的完整路径来解决问题