Java RandomAccessFile.readLong()

Syntax

RandomAccessFile.readLong() has the following syntax.

public final long readLong()   throws IOException

Example

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


//from  w  w  w . j  av  a2  s .  c  o  m
import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         long l = 12345676789098L;
         
         RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

         // write something in the file
         raf.writeLong(l);

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

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

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

         // write something in the file
         raf.writeLong(12345676789099L);

         raf.seek(0);
         System.out.println(raf.readLong());
      } catch (IOException ex) {
         ex.printStackTrace();
      }

   }
}