缓冲读卡器无法加载文件?

时间:2014-05-25 15:31:36

标签: java file intellij-idea bufferedreader fileinputstream

我正在为学校做一个项目,我想从文件中加载问题。但是,Java无法加载该文件。我确信文本文件的名称是正确的,并且在正确的指令中,但在这里它们是:

游戏> SRC game>src 游戏&GT朝外GT;生产>游戏 game>out>production>game

private static void init(){
    BufferedReader br = null;
    ArrayList<String> strings= new ArrayList<String>();
    try {

        String sCurrentLine;

        br = new BufferedReader(new FileReader(new File("questions.txt")));

        while ((sCurrentLine = br.readLine()) != null) {
            strings.add(sCurrentLine);
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    int i = 0;
    while(i < strings.size()){
        String text = strings.get(i++);
        int numAnswers = Integer.parseInt(strings.get(i++));
        ArrayList<String> answers = new ArrayList<String>();
        for (int i2 = 0; i2 < numAnswers; i2++){
            answers.add(strings.get(i++));
        }
        questions.add(new Question(text, answers));
    }
}

1 个答案:

答案 0 :(得分:0)

尝试scr/questions.txt作为路径。

br = new BufferedReader(new FileReader(new File("src/questions.txt")));