【问题标题】:Writing jama matrix to file将 jama 矩阵写入文件
【发布时间】:2014-06-03 18:31:18
【问题描述】:

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

【问题讨论】:

  • 我发现了错误。我们需要在打印矩阵后刷新写入器。

标签: java filewriter printwriter jama


【解决方案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();
}

【讨论】:

  • 问题是写入后没有刷新写入器。这是一个愚蠢的问题:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 2015-06-01
  • 2015-02-16
  • 1970-01-01
相关资源
最近更新 更多