Java IO Tutorial - Java DataInputStream .readFully (byte[] b)








Syntax

DataInputStream.readFully(byte[] b) has the following syntax.

public final void readFully(byte[] b)   throws IOException

Example

In the following code shows how to use DataInputStream.readFully(byte[] b) method.

// w  ww.  j a  v  a  2 s.co m
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
  public static void main(String[] args) throws IOException {
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    int length = dis.available();

    byte[] buf = new byte[length];

    dis.readFully(buf);

    for (byte b : buf) {
      char c = (char) b;
      System.out.print(c);
    }

  }
}