Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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();
        }

    }
}