首页 > 解决方案 > for Loop 2d 数组 BufferedWriter 未写入 txt

问题描述

我有这个代码:

        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 中写入任何内容。

标签: javaarraysfor-loopwriter

解决方案


推荐阅读