Home » Java programming language

Java RandomAccessFile getFilePointer() Method with Example

RandomAccessFile Class getFilePointer() method: Here, we are going to learn about the getFilePointer() method of RandomAccessFile Class with its syntax and example.
Submitted by Preeti Jain, on March 23, 2020

RandomAccessFile Class getFilePointer() method

  • getFilePointer() method is available in java.io package.
  • getFilePointer() method is used to get the current pointer in the RandomAccessFile stream.
  • getFilePointer() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getFilePointer() method does not throw an exception at the time of returning file pointer.


    public long getFilePointer();


  • It does not accept any parameter.

Return value:

The return type of this method is long, it returns the pointer from the starting of the file at which the next read or write happens.


// Java program to demonstrate the example 
// of long getFilePointer() method of
// RandomAccessFile

import java.io.*;

class RAFGetFilePointer {
 public static void main(String[] args) throws Exception {
  // Instantiate a random access file
  // object with file name and permissions
  RandomAccessFile ra_f = new RandomAccessFile("e:/includehelp.txt", "rw");

  // By using writeUTF() method is to 
  // write data in the file
  ra_f.writeUTF("Welcome, in Java World!!!");

  // Initially set the file pointer
  // is at 0 for reading the file

  // To read file content by using
  // readUTF()
  System.out.println("ra_f .readUTF(): " + ra_f.readUTF());

  // By using getFilePointer() method is to
  // return the file pointer in bytes at which
  // the next read/write occurs
  System.out.println("ra_f.getFilePointer(): " + ra_f.getFilePointer());

  // By using close() method isto
  // close this stream ran_f


ra_f .readUTF(): Welcome, in Java World!!!
ra_f.getFilePointer(): 27

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.