Java DataInputStream Read readBytes(File ff)

Here you can find the source of readBytes(File ff)

Description

read Bytes

License

Open Source License

Declaration

public static byte[] readBytes(File ff) throws IOException 

Method Source Code

//package com.java2s;
/*/*  ww  w.j a  v a2  s  .c  o m*/
 * Copyright (C) ${year} Omry Yadan <${email}>
 * All rights reserved.
 *
 * See https://github.com/omry/banana/blob/master/BSD-LICENSE for licensing information
 */

import java.io.*;

public class Main {
    public static byte[] readBytes(File ff) throws IOException {
        byte b[] = new byte[(int) ff.length()];
        DataInputStream din = new DataInputStream(new FileInputStream(ff));
        try {
            din.readFully(b);
        } finally {
            din.close();
        }
        return b;
    }

    public static void readFully(InputStream in, byte[] data) throws IOException {
        int len = data.length;
        int off = 0;

        int n = 0;
        while (n < len) {
            int count = in.read(data, off + n, len - n);
            if (count < 0)
                throw new EOFException();
            n += count;
        }
    }
}

Related

  1. loadIntArrayFromFile(File file)
  2. readBytes(DataInputStream dataStream, int numberOfBytes)
  3. readBytes(DataInputStream input, int size)
  4. readBytes(DataInputStream stream, int size)
  5. readBytes(DataInputStream stream, int size)
  6. readBytes(String filename)
  7. readBytes(String filename)
  8. readBytesArray(DataInputStream dis)
  9. readFromFile(File file)