Java DataOutputStream .writeDouble (double v)

Syntax

DataOutputStream.writeDouble(double v) has the following syntax.

public final void writeDouble(double v)   throws IOException

Example

In the following code shows how to use DataOutputStream.writeDouble(double v) method.


/*w  w  w  .jav a2  s.  com*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
  public static void main(String[] args) throws IOException {
    double[] dbuf = { 12.34, 34.45, 67.78, 88.88, 66.66, 77.33 };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (double d : dbuf) {
      dos.writeDouble(d);
    }
    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
      double c = dis.readDouble();
      System.out.print(c);
    }
  }
}