Example usage for java.io RandomAccessFile readDouble

List of usage examples for java.io RandomAccessFile readDouble

Introduction

In this page you can find the example usage for java.io RandomAccessFile readDouble.

Prototype

public final double readDouble() throws IOException 

Source Link

Document

Reads a double from this file.

Usage

From source file:InputOutputDemoPrimitive.java

public static void main(String[] a) throws Exception {

    //Read and write parts of file "raf.dat" in arbitrary order:
    RandomAccessFile raf = new RandomAccessFile("r.dat", "rw");
    raf.writeDouble(3.1415);//w w w  . ja  v a 2  s .c  o m
    raf.writeInt(42);
    raf.seek(0);
    System.out.println(raf.readDouble() + " " + raf.readInt());

}

From source file:Main.java

public static void main(String[] args) {
    try {/*w  w  w .  jav  a  2 s  . c o  m*/
        double d = 1234.5678;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeDouble(d);

        raf.seek(0);

        System.out.println(raf.readDouble());

        raf.seek(0);

        raf.writeDouble(123.4567);

        raf.seek(0);

        System.out.println(raf.readDouble());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from www.j a  va2s . c o  m*/
        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();
    }

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    RandomAccessFile raf = new RandomAccessFile("employee.dat", "rw");

    raf.writeUTF("J");
    raf.writeUTF("S");
    raf.writeDouble(4.0);//ww w . j  a  v a  2s . co  m
    raf.seek(0L);
    String fname = raf.readUTF();
    String lname = raf.readUTF();
    double salary = raf.readDouble();
    System.out.println("First name = " + fname);
    System.out.println("Last name = " + lname);
    System.out.println("Salary = " + salary);
    raf.close();
}

From source file:RandomIOApp.java

public static void main(String args[]) throws IOException {
    RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
    file.writeBoolean(true);//w w w.  jav  a  2  s . com
    file.writeInt(123456);
    file.writeChar('j');
    file.writeDouble(1234.56);
    file.seek(1);
    System.out.println(file.readInt());
    System.out.println(file.readChar());
    System.out.println(file.readDouble());
    file.seek(0);
    System.out.println(file.readBoolean());
    file.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    RandomAccessFile rf = new RandomAccessFile("test.dat", "rw");
    for (int i = 0; i < 10; i++)
        rf.writeDouble(i * 1.414);/*from  w w w .  j ava  2 s . c o m*/
    rf.close();
    rf = new RandomAccessFile("test.dat", "rw");
    rf.seek(5 * 8);
    rf.writeDouble(47.0001);
    rf.close();
    rf = new RandomAccessFile("test.dat", "r");
    for (int i = 0; i < 10; i++)
        System.out.println("Value " + i + ": " + rf.readDouble());
    rf.close();

}

From source file:CreateEmployeeFile.java

void read(RandomAccessFile raf) throws IOException {
    char[] temp = new char[15];
    for (int i = 0; i < temp.length; i++)
        temp[i] = raf.readChar();// w  ww. j  av a2 s  .co  m
    lastName = new String(temp);
    temp = new char[15];
    for (int i = 0; i < temp.length; i++)
        temp[i] = raf.readChar();
    firstName = new String(temp);
    temp = new char[30];
    for (int i = 0; i < temp.length; i++)
        temp[i] = raf.readChar();

    address = new String(temp);
    age = raf.readByte();
    salary = raf.readDouble();
}