Example usage for java.io DataOutputStream DataOutputStream

List of usage examples for java.io DataOutputStream DataOutputStream

Introduction

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

Prototype

public DataOutputStream(OutputStream out) 

Source Link

Document

Creates a new data output stream to write data to the specified underlying output stream.

Usage

From source file:Main.java

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

    long[] l = { 1234567890L, 987654321L };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (long j : l) {
        dos.writeLong(j);//from w w w  .j  av  a 2 s .co  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 {
    int[] i = { 123, 234, 345, 456, 678 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (int j : i) {
        dos.writeInt(j);//from  w  ww.  ja  va 2s . c  o m
    }
    dos.flush();

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

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

From source file:Main.java

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

    int[] i = { 123, 234, 454, 567, 789 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (int j : i) {
        dos.writeInt(j);//from www.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) {
        int k = dis.readInt();
        System.out.print(k);
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (byte j : b) {
        dos.writeByte(j);/* w  w  w  . jav a  2 s  . c  o  m*/
    }
    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        int k = dis.read();
        System.out.print(k);
        dis.skipBytes(1);
    }

}

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

    dos.writeChars(s);//from  ww  w  . ja v  a 2s.c  om

    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 {
    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. j a  va 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 {
    String[] s = { "Hello", "tutorial from java2s.com!!" };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (String j : s) {
        dos.writeUTF(j);//  w ww . j  a va 2  s. c  om
    }
    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 {

    String[] s = { "Hello", "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  .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) {
        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  w  w w.ja v  a  2 s  . c  om*/
    }
    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 {

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

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

    for (long j : l) {
        dos.writeLong(j);/*from  w  w w . ja v a 2 s. co 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);
    }
}