我想使用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);
答案 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();
}