DataInputStream

Generally you use a DataInputStream to read data written by a DataOutputStream. This format uses IEEE 754 for floating point data, big-endian format for integer data, and a modified UTF-8 for Unicode data.

DataInputStream has these methods:

 public DataInputStream(InputStream in)
 public final int read(byte[] input) throws IOException
 public final int read(byte[] input, int offset, int length) throws IOException
 public final void readFully(byte[] input) throws IOException
 public final void readFully(byte[] input, int offset, int length) 
  throws IOException
 public final int skipBytes(int n) throws IOException
 public final boolean readBoolean() throws IOException
 public final byte readByte() throws IOException
 public final int readUnsignedByte() throws IOException
 public final short readShort() throws IOException
 public final int readUnsignedShort() throws IOException
 public final char readChar() throws IOException
 public final int readInt() throws IOException
 public final long readLong() throws IOException
 public final float readFloat() throws IOException
 public final double readDouble() throws IOException
 public final String readUTF() throws IOException
 public static final String readUTF(DataInput in) throws IOException
The readFully() methods read repeatedly from the underlying stream until the byte array is filled. This contrasts with the regular read() methods which only read as many bytes as are available at the moment.

There's also a fairly common readLine() method that was used quite commonly in Java 1.0. However it's deprecated in favor of BufferedReader in Java 1.1


Previous | Next | Top
Last Modified July 6, 1999
Copyright 1997, 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu