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 {

    DataInputStream in3 = new DataInputStream(new ByteArrayInputStream("a dbcde".getBytes()));
    System.out.print((char) in3.readByte());
    in3.close();//from   w w  w.  j av a2s  . c om
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    DataInputStream in = new DataInputStream(new FileInputStream("Main.class"));

    int start = in.readInt();
    if (start != 0xcafebabe) {
        System.out.println("not valid");
    }//from   w ww.j  a  v  a  2s .co  m
    in.close();
    System.out.println(in.readUnsignedShort() + "/" + in.readUnsignedShort());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], 1234);
    DataInputStream dis = new DataInputStream(sock.getInputStream());
    float f = dis.readFloat();
    System.out.println("PI=" + f);
    dis.close();// w  w w.  j  a  v a2  s .  c om
    sock.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream("temp.tmp")));
    for (int i = 0; i < 10; i++)
        dis.readInt();//from  ww w. j av  a  2  s  .  c o  m
    dis.close();

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream("temp.tmp")));
    for (int i = 0; i < 10; i++)
        dis.readInt();//  w ww . j  a  v a 2 s  .co  m
    dis.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("C:/Long.txt");
    DataInputStream din = new DataInputStream(fin);
    long l = din.readLong();
    System.out.println("long : " + l);
    din.close();/*  w  w w.j  a  v a 2s . co m*/
}

From source file:Main.java

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

    byte b[] = new byte[10];
    din.read(b);//  www.jav  a  2  s .  co m
    din.close();
}

From source file:Main.java

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

    short s = din.readShort();
    System.out.println("short : " + s);
    din.close();// www .  j a va  2  s. com
}

From source file:Main.java

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

    float f = din.readFloat();
    System.out.println("float : " + f);
    din.close();// w ww.  j  ava  2s.  co m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Socket t = new Socket("127.0.0.1", 7);
    DataInputStream dis = new DataInputStream(t.getInputStream());
    PrintStream ps = new PrintStream(t.getOutputStream());
    ps.println("Hello");
    String str = dis.readUTF();// w  w  w. j av  a  2  s.  c om
    if (str.equals("Hello"))
        System.out.println("Alive!");
    else
        System.out.println("Dead");
    t.close();
}