Java IO Tutorial - Java RandomAccessFile .writeFloat (float v)








Syntax

RandomAccessFile.writeFloat(float v) has the following syntax.

public final void writeFloat(float v)   throws IOException

Example

In the following code shows how to use RandomAccessFile.writeFloat(float v) method.

/*from w  w  w.j a  v a2  s .c om*/

import java.io.*;

public class Main {

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

   }
}