0

我想通过使用 jama 库将矩阵写入 java 中的文件。但是,只生成了一个空文件。我正在使用下面的代码。有什么问题?

PrintWriter writer = null;
    try {
        writer = new PrintWriter("deneme.txt", "UTF-8");
    } catch (FileNotFoundException | UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    m3.print( writer,2,2);
4

1 回答 1

1

writer当涉及到这行代码时,可能为空。移动m3.print(writer,2,2);try 块的内部。

PrintWriter writer = null;
try {
    writer = new PrintWriter("deneme.txt", "UTF-8");
    m3.print(writer, 2, 2);
} catch (FileNotFoundException | UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
于 2014-06-03T18:37:30.063 回答