Create DataInputStream from FileInputStream and read different types of data : DataInputStream « File Input Output « Java






Create DataInputStream from FileInputStream and read different types of data

 

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

class DataInputStreamDemo {

  public static void main(String args[]) throws Exception {

    FileInputStream fis = new FileInputStream(args[0]);

    DataInputStream dis = new DataInputStream(fis);

    System.out.println(dis.readBoolean());
    System.out.println(dis.readByte());
    System.out.println(dis.readChar());
    System.out.println(dis.readDouble());
    System.out.println(dis.readFloat());
    System.out.println(dis.readInt());
    System.out.println(dis.readLong());
    System.out.println(dis.readShort());

    fis.close();
  }
}

   
  








Related examples in the same category

1.new DataInputStream(new BufferedInputStream(new FileInputStream()))
2.Read short type of data with DataInputStream
3.Read different data types from DataInputStream
4.Read boolean from file using DataInputStream
5.Read byte array from file using DataInputStream
6.Read byte from file using DataInputStream
7.Read char from file using DataInputStream
8.Read double from file using DataInputStream
9.Read float from file using DataInputStream
10.Read int from file using DataInputStream
11.Read long from file using DataInputStream
12.Read short from file using DataInputStream
13.Read unsigned byte from file using DataInputStream
14.Use DataInputStream to create double
15.Check the class version
16.DataOutputStream and DataInputStream: read and write by data types