Java I/O How to - Read int from buffered stream








Question

We would like to know how to read int from buffered stream.

Answer

/*from w w w .j  a  va 2 s  .  c  o  m*/
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws Exception {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(
        "temp.tmp")));
    for (int i = 0; i < 10; i++)
      dis.readInt();
    dis.close();

  }
}