Java DataInputStream Read saveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out)

Here you can find the source of saveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out)

Description

save Double Matrix From Binary

License

Open Source License

Declaration

public static void saveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out) 

Method Source Code

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

import java.io.DataInputStream;

import java.io.EOFException;
import java.io.IOException;
import java.io.PrintStream;

public class Main {
    public static void saveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out) {
        out.println(rows + " " + cols);
        for (int i = 0; i < rows; i++) {
            double[] row = readDoubleArrayFromFileBinary(reader, cols);
            for (int j = 0; j < cols; j++) {
                out.print(row[j]);//from   w  w w  .  jav a2s  . c  o  m
                if (j != cols - 1) {
                    out.print(" ");
                }
            }
            out.println();
        }
    }

    public static double[] readDoubleArrayFromFileBinary(DataInputStream storeReader, int dimensions) {
        double[] ret = new double[dimensions];
        for (int i = 0; i < dimensions; i++) {
            try {
                ret[i] = storeReader.readDouble();
            } catch (EOFException e) {
                return null;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return ret;
    }
}

Related

  1. readBytes(String filename)
  2. readBytes(String filename)
  3. readBytesArray(DataInputStream dis)
  4. readFromFile(File file)
  5. readFromFileToLineArray(File file)