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 Exception {

    String thisLine;//from www . j  a  va  2  s .  c  o  m
    URL u = new URL("http://www.google.com");
    DataInputStream theHTML = new DataInputStream(u.openStream());
    while ((thisLine = theHTML.readLine()) != null) {
        System.out.println(thisLine);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("C:/UnsignedByte.txt");
    DataInputStream din = new DataInputStream(fin);

    int i = din.readUnsignedByte();
    System.out.println("Unsinged byte value : " + i);
    din.close();//from  w w w  .  ja v a  2 s.com
}

From source file:lycos.java

public static void main(String[] args) {

    try {/*from   ww w  .  j  av a  2 s  .co m*/
        String thisLine;
        URL u = new URL("http://www.google.com");
        DataInputStream theHTML = new DataInputStream(u.openStream());
        while ((thisLine = theHTML.readLine()) != null) {
            System.out.println(thisLine);
        } // while loop ends here
    } catch (MalformedURLException e) {
        System.err.println(e);
    } catch (IOException e) {
        System.err.println(e);
    }

}

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;/*from   w  w  w  .ja  va  2  s . c om*/
    }
    System.out.println("\nAverage = " + sum / counter);
    dataIn.close();
    fileIn.close();
}

From source file:MainClass.java

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

    try {/*from   w  w  w .  j  ava  2s .  c om*/
        DataInputStream in3 = new DataInputStream(new ByteArrayInputStream("a dbcde".getBytes()));
        while (true)
            System.out.print((char) in3.readByte());
    } catch (EOFException e) {
        System.err.println("End of stream");
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("myfile.dat");

    DataInputStream din = new DataInputStream(fin);
    while (true) {
        int theNumber = din.readInt();
        //double theNumber = din.readDouble();
        //System.out.println(din.readUTF());
        //boolean b = din.readBoolean();
        byte b = din.readByte();
        System.out.println("byte : " + b);
        System.out.println(theNumber);

        char ch = din.readChar();
        System.out.println("Char : " + ch);
        float f = din.readFloat();
        System.out.println("float : " + f);
        long l = din.readLong();
        System.out.println("long : " + l);

    }/*from  w  ww. j av a2 s.co m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("c:\\test.txt");

    DataInput in = new DataInputStream(is);
    DataInputStream.readUTF(in);/*  www.j a v  a2  s.com*/

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    int length = dis.available();

    byte[] buf = new byte[length];

    dis.readFully(buf);/*from w ww  .  j ava2 s  .  c  o  m*/

    for (byte b : buf) {
        char c = (char) b;
        System.out.print(c);
    }

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    int length = dis.available();

    byte[] buf = new byte[length];

    dis.readFully(buf, 4, 5);/*  w ww. ja va  2 s .  c  o  m*/
    for (byte b : buf) {
        char c = '0';
        if (b != 0) {
            c = (char) b;
        }
        System.out.print(c);
    }

}

From source file:Main.java

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

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

    DataInputStream dis = new DataInputStream(is);

    int count = is.available();

    byte[] bs = new byte[count];

    dis.read(bs, 4, 3);//from   www.j a  v  a 2  s. c  o  m

    for (byte b : bs) {
        char c = (char) b;

        if (b == 0) {
            c = '0';
        }
        System.out.print(c);
    }
}