print Matrix To File - Java 2D Graphics

Java examples for 2D Graphics:Image File

Description

print Matrix To File

Demo Code


//package com.java2s;

import java.io.*;

public class Main {
    public static void printMatrixToFile(FileOutputStream out, double[][] A)
            throws IOException {
        int n = A.length;
        int m = A[0].length;

        StringBuffer sb = new StringBuffer(n + " " + m + "\r\n");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                sb.append(A[i][j] + " ");
            }//  w  w w.j  ava  2  s .c o m
            sb.append("\r\n");
        }

        out.write(sb.toString().getBytes());
    }

    public static void printMatrixToFile(FileOutputStream out, int[][] A)
            throws IOException {
        int n = A.length;
        int m = A[0].length;
        StringBuffer sb = new StringBuffer(n + " " + m + "\r\n");

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++)
                sb.append(A[i][j] + " ");
            sb.append("\r\n");
        }

        out.write(sb.toString().getBytes());
    }
}

Related Tutorials