Example usage for java.io RandomAccessFile writeDouble

List of usage examples for java.io RandomAccessFile writeDouble

Introduction

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

Prototype

public final void writeDouble(double v) throws IOException 

Source Link

Document

Converts the double argument to a long using the doubleToLongBits method in class Double , and then writes that long value to the file as an eight-byte quantity, high byte first.

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);
    raf.writeInt(42);/*from  w w  w . j av a2s  .com*/
    raf.seek(0);
    System.out.println(raf.readDouble() + " " + raf.readInt());

}

From source file:Main.java

public static void main(String[] args) {
    try {//from   w  ww  . ja  v a 2s .co 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 {/*ww  w .jav  a  2  s . c om*/
        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: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);
    rf.close();//w ww .  jav  a  2 s  .  c  om
    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: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);
    raf.seek(0L);//from  w  w  w  . j  a v a2s  .c o m
    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  ww .  j av a  2  s.  c  om
    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:CreateEmployeeFile.java

void write(RandomAccessFile raf) throws IOException {
    StringBuffer sb;//from www  .  j ava 2s .  c  o m
    if (lastName != null)
        sb = new StringBuffer(lastName);
    else
        sb = new StringBuffer();

    sb.setLength(15);
    raf.writeChars(sb.toString());

    if (firstName != null)
        sb = new StringBuffer(firstName);
    else
        sb = new StringBuffer();

    sb.setLength(15);
    raf.writeChars(sb.toString());

    if (address != null)
        sb = new StringBuffer(address);
    else
        sb = new StringBuffer();

    sb.setLength(30);
    raf.writeChars(sb.toString());
    raf.writeByte(age);
    raf.writeDouble(salary);
}