for Loop 2d array BufferedWriter没有写入txt

时间:2018-05-06 18:23:54

标签: java arrays for-loop writer

我有这段代码:

        try {
        File file = new File("newbook.txt");
        FileWriter fw = new FileWriter(file, true);
        BufferedWriter out = new BufferedWriter(fw);
        if (!file.exists()) {
            file.createNewFile();
        }
        for (int r = 0; r < StuGrades.length; r++) {
            for (int c = 0; c < StuGrades[0].length; c++) {
                //out.write(StuGrades[r][c]);
                out.write(" " + StuGrades[r][c]);
            }
        }
    }catch(IOException e){
        System.out.println("something's wrong");
    }

它不会运行任何错误,但它不会在txt中写入任何内容。

0 个答案:

没有答案