Example usage for java.io RandomAccessFile writeFloat

List of usage examples for java.io RandomAccessFile writeFloat

Introduction

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

Prototype

public final void writeFloat(float v) throws IOException 

Source Link

Document

Converts the float argument to an int using the floatToIntBits method in class Float , and then writes that int value to the file as a four-byte quantity, high byte first.

Usage

From source file:Main.java

public static void main(String[] args) {
    try {/* w w  w  .ja va 2  s. c om*/
        float f = 1234.5678f;

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

        raf.writeFloat(f);

        raf.seek(0);

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

        raf.seek(0);

        raf.writeFloat(123.4567f);

        raf.seek(0);

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

}

From source file:Main.java

public static void main(String[] args) {
    try {//  w  w  w .j  ava  2s .  c om
        float f = 1234.56f;

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

        // write something in the file
        raf.writeFloat(987.654f);

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

        // read float
        System.out.println(raf.readFloat());

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

        // write a float
        raf.writeFloat(f);

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

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

}