Java RandomAccessFile.writeInt(int v)

Syntax

RandomAccessFile.writeInt(int v) has the following syntax.

public final void writeInt(int v)   throws IOException

Example

In the following code shows how to use RandomAccessFile.writeInt(int v) method.


/*from   w  w w.  j a v a2s.c o  m*/
import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         int f = 1234;

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

         raf.writeInt(f);

         raf.seek(0);

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

         raf.seek(0);

         raf.writeInt(200);

         raf.seek(0);

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

   }
}