Java IO Tutorial - Java RandomAccessFile .writeBoolean (boolean v)








Syntax

RandomAccessFile.writeBoolean(boolean v) has the following syntax.

public final void writeBoolean(boolean v)   throws IOException

Example

In the following code shows how to use RandomAccessFile.writeBoolean(boolean v) method.

// w ww . j ava  2s  .  co  m


import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         boolean b = true;
         RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

         raf.writeBoolean(false);

         raf.seek(0);

         System.out.println(raf.readBoolean());

         raf.writeBoolean(b);

         raf.seek(1);

         System.out.println(raf.readBoolean());
         raf.close();
      } catch (IOException ex) {
         ex.printStackTrace();
      }

   }
}