Here we are creating object of RandomAccessFile for writing file we are using writeLong(),writeInt() , writeBoolean() method and for printing we use readBoolean(),readInt(). readLong()Refer below code for more understanding
import java.io.*;
class FileExample7
{
public static void main(String args[])
{
try
{
RandomAccessFile rac=new RandomAccessFile("d:/assignments/mydata.dat","rw");
rac.writeInt(1024);
rac.writeDouble(456.45);
rac.writeLong(40000);
rac.writeBoolean(true);
System.out.println("File size is "+rac.length()+ " bytes");
rac.seek(4);
double a=rac.readDouble();
System.out.println("The double value is "+a);
rac.close();
}
catch(Exception ex)
{
System.out.println("Error in writing or reading Object");
}
}
}