Java RandomAccessFile.readFloat()

Syntax

RandomAccessFile.readFloat() has the following syntax.

public final float readFloat()   throws IOException

Example

In the following code shows how to use RandomAccessFile.readFloat() method.


//from  www  .j a v  a 2  s. c o m

import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         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();
      }

   }
}