Java DataInputStream Read readBytes(String filename)

Here you can find the source of readBytes(String filename)

Description

read Bytes

License

LGPL

Declaration

private static byte[] readBytes(String filename) throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    private static byte[] readBytes(String filename) throws IOException {
        File file = new File(filename);
        FileInputStream fileInputStream = new FileInputStream(file);
        DataInputStream dataInputStream = new DataInputStream(fileInputStream);
        try {// ww w  .ja  va2  s .c om
            byte[] keyBytes = new byte[(int) file.length()];
            dataInputStream.readFully(keyBytes);
            return keyBytes;
        } finally {
            dataInputStream.close();
        }
    }
}

Related

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