Java Matrix Save to File MatrixToFile(double[][] matrix, String path)

Here you can find the source of MatrixToFile(double[][] matrix, String path)

Description

Matrix To File

License

Open Source License

Declaration

public static void MatrixToFile(double[][] matrix, String path) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static void MatrixToFile(double[][] matrix, String path) throws Exception {
        FileWriter f = new FileWriter(new File(path));
        for (int j = 0; j < matrix.length; j++) {
            if (j > 0) {
                f.write("\n");
            }/* w ww.  j  a  v  a 2s.  c  o m*/
            for (int i = 0; i < matrix[0].length; i++) {
                if (i > 0) {
                    f.write(",");
                }
                f.write(String.valueOf(matrix[j][i]));
            }
        }
        int rows = matrix.length;
        int cols = matrix[0].length;
        System.out.println("util.MatrixToFile: " + rows + "x" + cols + " -> " + path);

        f.flush();
        f.close();
    }
}