Example usage for java.io RandomAccessFile readBoolean

List of usage examples for java.io RandomAccessFile readBoolean

Introduction

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

Prototype

public final boolean readBoolean() throws IOException 

Source Link

Document

Reads a boolean from this file.

Usage

From source file:Main.java

public static void main(String[] args) {
    try {/*from ww w.  j  a va2s .c  om*/
        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();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from www.  j a  va2  s  .  c  om*/

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        // write something in the file
        raf.writeUTF("Hello World from java2s.com");

        // set the file pointer at 0 position
        raf.seek(0);

        // read boolean
        System.out.println(raf.readBoolean());

        // set the file pointer at 0 position
        raf.seek(0);

        // write 0 at the start
        raf.write(0);

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

}

From source file:RandomIOApp.java

public static void main(String args[]) throws IOException {
    RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
    file.writeBoolean(true);/*from w ww .  j  ava 2  s .c  o  m*/
    file.writeInt(123456);
    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();
}