Home » Java programming language

Java RandomAccessFile readInt() Method with Example

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

RandomAccessFile Class readInt() method

  • readInt() method is available in package.
  • readInt() method is used to read signed 32-bit integer value from this RandomAccessFile.
  • readInt() 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.
  • readInt() method may throw an exception at the time of reading integer.
    • IOException: This exception may throw an exception while performing input/output operation.
    • EOFException: This exception may throw when the file pointer reaches EOF (End-Of-File) before reading 4 bytes.


    public final int readInt();


  • It does not accept any parameter.

Return value:

The return type of this method is int, it returns the 4 bytes of data from this RandomAccessFile manipulated as an int value.


// Java program to demonstrate the example 
// of int readInt() method of
// RandomAccessFile


class RAFReadInt {
 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 writeFloat() method is to 
  // write float to the file

  // Initially set the file pointer
  // is at 1 for reading the file;

  // By using readInt() method is to 
  // read int upto signed 4 bytes 
  // from the file

  int i = ra_f.readInt();
  System.out.println("ra_f.readInt(): " + i);

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


ra_f.readInt(): 128210


Comments and Discussions



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

© some rights reserved.