Java Blog

 
 
 
import java.io.*;

class  ReadWritePrimitive
{
    public static void main(String[] args) 
    {
           try{
                FileOutputStream fos = new FileOutputStream(\"data.txt\");
                DataOutputStream dos = new DataOutputStream(fos);

                //Writing primitive data to the data.txt file
                dos.writeInt(2000);
                dos.writeDouble(888.88);
                dos.writeChar(\'V\');
                dos.writeBoolean(false);
                fos.close();
                dos.close();

               //Reading primitive data to the data.txt file
               FileInputStream fis = new FileInputStream(\"data.txt\");
               DataInputStream dis = new DataInputStream(fis);
               System.out.println(dis.readInt());
               System.out.println(dis.readDouble());
               System.out.println(dis.readChar());
               System.out.println(dis.readBoolean());
               fis.close();
               dis.close();
             }catch(Exception e) {}

    }
}

 
 
Didn't find what you were looking for? Find more on Program of reading and writing primitive data