将jama矩阵写入文件

时间:2014-06-03 18:31:18

标签: java filewriter printwriter jama

我想使用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);

1 个答案:

答案 0 :(得分:1)

当涉及到这行代码时,

writer可能为null。移动try块内的m3.print(writer,2,2);

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();
}