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








Syntax

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

public final int read(byte[] b)  throws IOException

Example

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

/*from   w w w . j  a  v a2s  .  c  o m*/
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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 count = is.available();

    byte[] bs = new byte[count];

    dis.read(bs);

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

  }
}