Example usage for java.io RandomAccessFile writeBoolean

List of usage examples for java.io RandomAccessFile writeBoolean

Introduction

In this page you can find the example usage for java.io RandomAccessFile writeBoolean.

Prototype

public final void writeBoolean(boolean v) throws IOException 

Source Link

Document

Writes a boolean to the file as a one-byte value.

Usage

From source file:RandomIOApp.java

public static void main(String args[]) throws IOException {
    RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
    file.writeBoolean(true);
    file.writeInt(123456);/*from w  w w.  ja  va2s. c om*/
    file.writeChar('j');
    file.writeDouble(1234.56);
    file.seek(1);
    System.out.println(file.readInt());
    System.out.println(file.readChar());
    System.out.println(file.readDouble());
    file.seek(0);
    System.out.println(file.readBoolean());
    file.close();
}

From source file:Main.java

public static void main(String[] args) {
    try {//from   ww w .j av a2s  .  com
        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();
    }

}