Home » Java programming language

Java RandomAccessFile readDouble() Method with Example

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

RandomAccessFile Class readDouble() method

  • readDouble() method is available in java.io package.
  • readDouble() method is used to read the double value from this RandomAccessFile and initially it takes long value by using readLong() method and convert the long value to a double by using longBitsToDouble() method.
  • readDouble() 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.
  • readDouble() method may throw an exception at the time of reading double.
    • 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 8 bytes.

Syntax:

    public final double readDouble();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is double, it returns the eight bytes of this RandomAccessFile manipulated as a double value.

Example:

// Java program to demonstrate the example 
// of double readDouble() method of
// RandomAccessFile

import java.io.*;

class RAFReadDouble {
 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 writeChar() method is to 
  // write character to the file
  ra_f.writeDouble(10025.358);

  // Initially set the file pointer
  // is at 2 for reading the file
  ra_f.seek(2);

  // By using readDouble() method is to 
  // read double from the file

  double d = ra_f.readDouble();
  System.out.println("ra_f.readDouble(): " + d);

  // By using close() method isto
  // close this stream ran_f
  ra_f.close();
 }
}

Output

ra_f.readDouble(): -4.5358523898723415E-209






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.