Writing jama matrix to file

428 Views Asked by At

I want to write a matrix to a file in java by using jama library.However, only a empty file is produced. I am using the code below. What can be wrong?

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

There are 1 best solutions below

1
On

writer could be null when it comes to this line of code. Move the m3.print(writer,2,2); inside of the try block.

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