Java I/O How to - Read byte array from a file using DataInputStream








Question

We would like to know how to read byte array from a file using DataInputStream.

Answer

/* w w  w  .ja  v  a2s . co m*/
import java.io.DataInputStream;
import java.io.FileInputStream;

public class Main {

  public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("C:/Array.txt");
    DataInputStream din = new DataInputStream(fin);

    byte b[] = new byte[10];
    din.read(b);
    din.close();
  }
}