Example usage for java.io DataInputStream DataInputStream

List of usage examples for java.io DataInputStream DataInputStream

Introduction

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

Prototype

public DataInputStream(InputStream in) 

Source Link

Document

Creates a DataInputStream that uses the specified underlying InputStream.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    String[] s = { "Hello", "from java2s.com!" };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (String j : s) {
        dos.writeUTF(j);/*from w  w w.  jav a2  s .c  o  m*/
    }

    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        String k = dis.readUTF();
        System.out.print(k);
    }
}

From source file:Main.java

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

    long[] l = { 1234567898765L, 12345678909876L };

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

    for (long j : l) {
        dos.writeLong(j);/*from  www.  jav a2 s.  c  o m*/
    }
    dos.flush();

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

    while (dis.available() > 0) {
        long k = dis.readLong();
        System.out.print(k);
    }
}

From source file:Main.java

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

    String[] s = { "Hello", "java2s.com!" };

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

    DataOutputStream dos = new DataOutputStream(fos);

    for (String j : s) {
        dos.writeUTF(j);//  w  w  w .  j  av a 2  s  . com
    }

    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        String k = dis.readUTF();
        System.out.print(k);
    }

}

From source file:Main.java

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

    byte[] buf = { 65, 66, 67, 68, 69, 70 };

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

    DataOutputStream dos = new DataOutputStream(fos);

    for (byte b : buf) {
        dos.writeChar(b);/*from ww w.  java  2s  .  c o  m*/
    }
    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);

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

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    float[] fbuf = { 12.34f, 23.34f, 45.56f, 67.78f, 12.55f, 77.88f };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (float f : fbuf) {
        dos.writeFloat(f);//  ww w.ja v a  2s. c  o m
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

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

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);/*from   w  w w.ja v  a2 s  . co  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:SquareClient.java

public static void main(String args[]) throws Exception {
    String server = args[0];/*  ww  w  .  j a  v a  2  s.  co 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:whois.java

public static void main(String[] args) {

    Socket theSocket;//from   w  w w  . ja va2 s  .  c om
    DataInputStream theWhoisStream;
    PrintStream ps;

    try {
        theSocket = new Socket(hostname, port, true);
        ps = new PrintStream(theSocket.getOutputStream());
        for (int i = 0; i < args.length; i++)
            ps.print(args[i] + " ");
        ps.print("\r\n");
        theWhoisStream = new DataInputStream(theSocket.getInputStream());
        String s;
        while ((s = theWhoisStream.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

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);//from w w  w . java 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[] args) throws IOException {

    float[] fbuf = { 123.345f, 234.567f, 123.123f, 123.123f, 123.123f, 123.345f };

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

    for (float f : fbuf) {
        dos.writeFloat(f);/*from  w w  w . ja  va  2 s. c om*/
    }

    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        float c = dis.readFloat();
        System.out.print(c + " ");
    }
}