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 {
    short[] s = { -5, 32767 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (short j : s) {
        dos.writeShort(j);//from  w w  w . ja 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) {
        int k = dis.readUnsignedShort();
        System.out.print(k);
    }
}

From source file:Main.java

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

    byte[] b = { -123, 4 };

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

    for (byte j : b) {
        dos.writeByte(j);/*  w  w  w .  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) {
        int k = dis.readUnsignedByte();
        System.out.print(k);
    }

}

From source file:Main.java

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

    for (short j : s) {
        dos.writeShort(j);/*from  w  ww  .j  a v a2 s.  c  om*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        short k = dis.readShort();
        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);//ww  w.  j ava2s .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[] 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.j a va  2 s . co 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 {

    long[] l = { 1234567890L, 987654321L };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (long j : l) {
        dos.writeLong(j);/*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) {
        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, 454, 567, 789 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (int j : i) {
        dos.writeInt(j);//  ww  w .  jav  a2  s .com
    }
    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 {
    short[] s = { 123, 234 };

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

    DataOutputStream dos = new DataOutputStream(fos);

    for (short j : s) {
        dos.writeShort(j);/*  w ww .j av a  2s. c o m*/
    }

    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        short k = dis.readShort();
        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.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) {
        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", "tutorial from java2s.com!!" };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (String j : s) {
        dos.writeUTF(j);/*from  ww w  .  j  a  v 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);
    }

}