Java DataInputStream read primitive types from file
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; public class Main { public static void main(String[] args) { String srcFile = "Main.dat"; try (DataInputStream dis = new DataInputStream(new FileInputStream(srcFile))) { System.out.println(dis.readInt()); System.out.println(dis.readDouble()); System.out.println(dis.readBoolean()); System.out.println(dis.readUTF()); } catch (IOException e) { e.printStackTrace();//from ww w . j av a 2 s . c om } } }