Example usage for java.io DataInputStream readDouble

List of usage examples for java.io DataInputStream readDouble

Introduction

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

Prototype

public final double readDouble() throws IOException 

Source Link

Document

See the general contract of the readDouble method of DataInput.

Usage

From source file:SquareClient.java

public static void main(String args[]) throws Exception {
    String server = args[0];//  w  w w .  j av a  2  s. c o m
    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: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);/*from w ww.ja  v a2s  . co  m*/
    out.writeInt(1000);
    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: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.ja  va 2s .c o  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: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);/* w w  w. j av  a 2 s.  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);/*  w w  w . j  av  a2 s  .  com*/
    out2.writeUTF("Square root of 2");
    out2.close();

    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);//  www  . 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 {
    FileInputStream fileIn = new FileInputStream("data.txt");
    DataInputStream dataIn = new DataInputStream(fileIn);
    System.out.println(dataIn.readUTF());
    int counter = dataIn.readInt();
    double sum = 0.0;
    for (int i = 0; i < counter; i++) {
        double current = dataIn.readDouble();
        System.out.println("Just read " + current);
        sum += current;/*  www  .j a  v  a  2  s. com*/
    }
    System.out.println("\nAverage = " + sum / counter);
    dataIn.close();
    fileIn.close();
}

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 ww .j a va  2 s  . com

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

From source file:MainClass.java

public static void main(String args[]) {
    try {/*from www .  j  a v a 2s .  com*/

        FileInputStream fis = new FileInputStream("fileName.dat");

        // Create a data input stream
        DataInputStream dis = new DataInputStream(fis);

        // Read and display data
        System.out.println(dis.readBoolean());
        System.out.println(dis.readByte());
        System.out.println(dis.readChar());
        System.out.println(dis.readDouble());
        System.out.println(dis.readFloat());
        System.out.println(dis.readInt());
        System.out.println(dis.readLong());
        System.out.println(dis.readShort());

        // Close file input stream
        fis.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:DataIODemo.java

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

    // write the data out
    DataOutputStream out = new DataOutputStream(new FileOutputStream("invoice1.txt"));

    double[] prices = { 19.99, 9.99, 15.99, 3.99, 4.99 };
    int[] units = { 12, 8, 13, 29, 50 };
    String[] descs = { "Java T-shirt", "Java Mug", "Duke Juggling Dolls", "Java Pin", "Java Key Chain" };

    for (int i = 0; i < prices.length; i++) {
        out.writeDouble(prices[i]);/*from w ww.ja  v  a  2 s  .co  m*/
        out.writeChar('\t');
        out.writeInt(units[i]);
        out.writeChar('\t');
        out.writeChars(descs[i]);
        out.writeChar('\n');
    }
    out.close();

    // read it in again
    DataInputStream in = new DataInputStream(new FileInputStream("invoice1.txt"));

    double price;
    int unit;
    StringBuffer desc;
    double total = 0.0;

    try {
        while (true) {
            price = in.readDouble();
            in.readChar(); // throws out the tab
            unit = in.readInt();
            in.readChar(); // throws out the tab
            char chr;
            desc = new StringBuffer(20);
            char lineSep = System.getProperty("line.separator").charAt(0);
            while ((chr = in.readChar()) != lineSep)
                desc.append(chr);
            System.out.println("You've ordered " + unit + " units of " + desc + " at $" + price);
            total = total + unit * price;
        }
    } catch (EOFException e) {
    }
    System.out.println("For a TOTAL of: $" + total);
    in.close();
}