Java RandomAccessFile.readDouble()
Syntax
RandomAccessFile.readDouble() has the following syntax.
public final double readDouble() throws IOException
Example
In the following code shows how to use RandomAccessFile.readDouble() method.
/*www. j a va 2 s. co m*/
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
double d = 1.2345678;
RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");
raf.writeDouble(123.456789);
// set the file pointer at 0 position
raf.seek(0);
System.out.println(raf.readDouble());
// set the file pointer at 0 position
raf.seek(0);
// write a double at the start
raf.writeDouble(d);
// set the file pointer at 0 position
raf.seek(0);
// read double
System.out.println(raf.readDouble());
raf.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »