Example usage for java.io DataOutputStream writeDouble

List of usage examples for java.io DataOutputStream writeDouble

Introduction

In this page you can find the example usage for java.io DataOutputStream 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 underlying output stream as an 8-byte quantity, high byte first.

Usage

From source file:SquareClient.java

public static void main(String args[]) throws Exception {
    String server = args[0];/*from w  w w .j  a  va2s . c om*/
    int port = Integer.parseInt(args[1]);
    double value = Double.valueOf(args[2]).doubleValue();

    Socket s = new Socket(server, port);
    OutputStream os = s.getOutputStream();
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeDouble(value);

    InputStream is = s.getInputStream();
    DataInputStream dis = new DataInputStream(is);
    value = dis.readDouble();

    System.out.println(value);
    s.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String strFilePath = "C:/Double.txt";
    FileOutputStream fos = new FileOutputStream(strFilePath);
    DataOutputStream dos = new DataOutputStream(fos);
    double d = 1;
    dos.writeDouble(d);
    dos.close();//from w  w  w.  j a v a  2s.  c o m
}

From source file:SquareServer.java

public static void main(String args[]) throws Exception {
    int port = Integer.parseInt(args[0]);
    ServerSocket ss = new ServerSocket(port);
    while (true) {
        Socket s = ss.accept();//from  w  w  w  .j  ava2  s .co  m
        InputStream is = s.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        double value = dis.readDouble();
        value *= value;

        OutputStream os = s.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeDouble(value);

        s.close();
    }
}

From source file:DataIODemo.java

public static void main(String args[]) throws IOException {

    FileOutputStream fout = new FileOutputStream("Test.dat");
    DataOutputStream out = new DataOutputStream(fout);

    out.writeDouble(98.6);
    out.writeInt(1000);// www  .  j  a v a2s  . c o m
    out.writeBoolean(true);

    out.close();

    FileInputStream fin = new FileInputStream("Test.dat");
    DataInputStream in = new DataInputStream(fin);

    double d = in.readDouble();
    int i = in.readInt();
    boolean b = in.readBoolean();

    System.out.println("Here are the values:  " + d + " " + i + " " + b);

    in.close();
}

From source file:Main.java

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);
    }/*www.  ja v a 2s .  c om*/
    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);
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt")));
    out2.writeDouble(3.14159);
    out2.writeUTF("Square root of 2");
    out2.close();/*from  w w  w .  j av a  2s .c o m*/

    DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt")));

    System.out.println(in5.readDouble());
    System.out.println(in5.readUTF());
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    double[] dbuf = { 65.56, 66.89, 67.98, 68.82, 69.55, 70.37 };

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

    DataOutputStream dos = new DataOutputStream(fos);

    for (double d : dbuf) {
        dos.writeDouble(d);
    }// w  ww .j  a v  a  2  s  .  c o m

    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 + " ");
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileOutputStream fileOut = new FileOutputStream("data.txt");
    BufferedOutputStream buffer = new BufferedOutputStream(fileOut);
    DataOutputStream dataOut = new DataOutputStream(buffer);
    dataOut.writeUTF("Hello!");
    dataOut.writeInt(4);// www.  ja v  a 2s . c  om
    dataOut.writeDouble(100.0);
    dataOut.close();
    buffer.close();
    fileOut.close();
}

From source file:MainClass.java

public static void main(String args[]) {
    try {//from w  w  w .j a  va2 s  .com

        FileOutputStream fos = new FileOutputStream(args[0]);

        DataOutputStream dos = new DataOutputStream(fos);

        dos.writeBoolean(false);
        dos.writeByte(Byte.MAX_VALUE);
        dos.writeChar('A');
        dos.writeDouble(Double.MAX_VALUE);
        dos.writeFloat(Float.MAX_VALUE);
        dos.writeInt(Integer.MAX_VALUE);
        dos.writeLong(Long.MAX_VALUE);
        dos.writeShort(Short.MAX_VALUE);

        fos.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 };
    DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat")));
    fout.writeInt(data.length);/*from   w  w  w.j ava 2 s . co m*/

    for (double d : data)
        fout.writeDouble(d);

    DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat")));
    int num = fin.readInt();

    double avg = 0.0;
    double d;

    for (int i = 0; i < num; i++) {
        d = fin.readDouble();
        avg += d;
        System.out.print(d + " ");
    }
    fin.close();
    fout.close();
}