Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Java Developer's Reference

Chapter 31 -- Package java.io

Chapter 31

Package java.io


CONTENTS




The Java I/O package, also known as java.io, gives classes support for reading and writing data to and from different input and output devices, including files, strings, and other data sources. The I/O package includes classes for inputting streams of data, outputting streams of data, working with files, and tokenizing streams of data. Table 31.1 shows the contents of the java.io package, and Figure 31.1 illustrates the contents' hierarchy.

Figure 31.1: Contents of the java.io package.

Table 31.1. Contents of the java.io package.

Class indexException index Interface index
BufferedInputStream EOFException DataInput
BufferedOutputStream FileNotFoundException DataOutput
ByteArrayInputStream InterruptedIOException FilenameFilter
ByteArrayOutputStream IOException  
DataInputStream UTFDataFormatException  
DataOutputStream   
File   
FileDescriptor   
FileInputStream   
FileOutputStream   
FilterInputStream   
FilterOutputStream   
InputStream   
LineNumberInputStream   
OutputStream   
PipedInputStream   
PipedOutputStream   
PrintStream   
PushbackInputStream   
RandomAccessFile   
SequenceInputStream   
StreamTokenizer   
StringBufferInputStream   

DataInput

Object

See also: DataInputStream, DataOutput.

The DataInput interface describes an input stream that can read input data in a platform-independent manner; here is its definition:

public interface java.io.DataInput {
   // Methods
   public abstract boolean readBoolean();
   public abstract byte readByte();
   public abstract char readChar();
   public abstract double readDouble();
   public abstract float readFloat();
   public abstract void readFully(byte b[]);
   public abstract void readFully(byte b[], int off, int len);
   public abstract int readInt();
   public abstract String readLine();
   public abstract long readLong();
   public abstract short readShort();
   public abstract int readUnsignedByte();
   public abstract int readUnsignedShort();
   public abstract String readUTF();
   public abstract int skipBytes(int n);
}

readBoolean

DataInput

public abstract boolean readBoolean() throws IOException

This method reads a Boolean value (byte) from the input stream. A value of 0 is interpreted as false, but all other values are interpreted as true.

the Boolean value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadByte

DataInput

public abstract byte readByte() throws IOException

This method reads a signed byte (8-bit) value from the input stream.

the byte value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadChar

DataInput

public abstract char readChar() throws IOException

This method reads a Unicode character (16-bit) value from the input stream.

the Unicode character value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadDouble

DataInput

public abstract double readDouble() throws IOException

This method reads a double (64-bit) value from the input stream.

the double value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadFloat

DataInput

public abstract float readFloat() throws IOException

This method reads a float (32-bit) value from the input stream.

the float value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadFully

DataInput

public abstract void readFully(byte b[]) throws IOException

This method reads up to b.length bytes from the input stream into the byte array b, blocking until all bytes are read.

b is the byte array into which the data is read.

EOFException if the end of the stream is reached before reading the specified number of bytes.

IOException if an I/O error occurs.

ReadFully

DataInput

public abstract void readFully(byte b[], int off, int len) throws IOException

This method reads up to len bytes from the input stream into the byte array b beginning off bytes into the array, blocking until all bytes are read.

b is the byte array into which the data is read.

off is the starting offset into the array for the data to be written to.

len is the maximum number of bytes to read.

EOFException if the end of the stream is reached before reading the specified number of bytes.

IOException if an I/O error occurs.

ReadInt

DataInput

public abstract int readInt() throws IOException

This method reads an integer (32-bit) value from the input stream.

the integer value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadLine

DataInput

public abstract String readLine() throws IOException

This method reads a line of text from the input stream.

a string containing the line of text read.

EOFException if the end of the stream is reached before reading the line of text.

IOException if an I/O error occurs.

ReadLong

DataInput

public abstract long readLong() throws IOException

This method reads a long (64-bit) value from the input stream.

the long value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadShort

DataInput

public abstract short readShort() throws IOException

This method reads a short (16-bit) value from the input stream.

the short value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadUnsignedByte

DataInput

public abstract int readUnsignedByte() throws IOException

This method reads an unsigned byte (8-bit) value from the input stream.

the unsigned byte value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadUnsignedShort

DataInput

public abstract int readUnsignedShort() throws IOException

This method reads an unsigned short (16-bit) value from the input stream.

the short value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadUTF

DataInput

public abstract String readUTF() throws IOException

This method reads a string encoded by using a modified UTF-8 format from the input stream.

the string read.

EOFException if the end of the stream is reached before reading the string.

UTFDataFormatException if the bytes read do not represent a valid UTF-8 encoding of a string.

IOException if an I/O error occurs.

SkipBytes

DataInput

public abstract int skipBytes(int n) throws IOException

This method skips n bytes of data in the input stream, blocking until all bytes are skipped.

n is the number of bytes to skip.

the actual number of bytes skipped.

EOFException if the end of the stream is reached before skipping the specified number of bytes.

IOException if an I/O error occurs.

DataOutput

Object

See also: DataOutputStream, DataInput.

The DataOutput interface describes an output stream that can write output data in a platform-independent manner; this is its definition:

public interface java.io.DataOutput {
   // Methods
   public abstract void write(byte b[]);
   public abstract void write(byte b[], int off, int len)
   public abstract void write(int b);
   public abstract void writeBoolean(boolean v);
   public abstract void writeByte(int v);
   public abstract void writeBytes(String s);
   public abstract void writeChar(int v);
   public abstract void writeChars(String s);
   public abstract void writeDouble(double v);
   public abstract void writeFloat(float v);
   public abstract void writeInt(int v);
   public abstract void writeLong(long v);
   public abstract void writeShort(int v);
   public abstract void writeUTF(String str);
}

write

DataOutput

public abstract void write(byte b[]) throws IOException

This method writes b.length bytes to the output stream from the byte array b, blocking until all bytes are written.

b is the byte array from which the data is written.

IOException if an I/O error occurs.

Write

DataOutput

public abstract void write(byte b[], int off, int len) throws IOException

This method writes len bytes to the output stream from the byte array b beginning off bytes into the array, blocking until all bytes are written.

b is the byte array from which the data is written.

off is the starting offset into the array for the data to be read from.

len is the number of bytes to write.

IOException if an I/O error occurs.

Write

DataOutput

public abstract void write(int b) throws IOException

This method writes a byte value to the output stream, blocking until the byte is written.

b is the byte value to be written.

IOException if an I/O error occurs.

WriteBoolean

DataOutput

public abstract void writeBoolean(boolean v) throws IOException

This method writes a Boolean value to the output stream. The Boolean value true is written as the byte value 1, and false is written as the byte value 0.

v is the Boolean value to be written.

IOException if an I/O error occurs.

WriteByte

DataOutput

public abstract void writeByte(int v) throws IOException

This method writes a byte (8-bit) value to the output stream.

v is the byte value to be written.

IOException if an I/O error occurs.

WriteBytes

DataOutput

public abstract void writeBytes(String s) throws IOException

This method writes a string to the output stream as a sequence of bytes.

s is the string to be written as bytes.

IOException if an I/O error occurs.

WriteChar

DataOutput

public abstract void writeChar(int v) throws IOException

This method writes a character (16-bit) value to the output stream.

v is the character value to be written.

IOException if an I/O error occurs.

WriteChars

DataOutput

public abstract void writeChars(String s) throws IOException

This method writes a string to the output stream as a sequence of characters.

s is the string to be written as characters.

IOException if an I/O error occurs.

WriteDouble

DataOutput

public abstract void writeDouble(double v) throws IOException

This method writes a double (64-bit) value to the output stream.

v is the double value to be written.

IOException if an I/O error occurs.

WriteFloat

DataOutput

public abstract void writeFloat(float v) throws IOException

This method writes a float (32-bit) value to the output stream.

v is the float value to be written.

IOException if an I/O error occurs.

WriteInt

DataOutput

public abstract void writeInt(int v) throws IOException

This method writes an integer (32-bit) value to the output stream.

v is the integer value to be written.

IOException if an I/O error occurs.

WriteLong

DataOutput

public abstract void writeLong(long v) throws IOException

This method writes a long (64-bit) value to the output stream.

v is the long value to be written.

IOException if an I/O error occurs.

WriteShort

DataOutput

public abstract void writeShort(int v) throws IOException

This method writes a short (16-bit) value to the output stream.

v is the short value to be written.

IOException if an I/O error occurs.

WriteUTF

DataOutput

public abstract void writeUTF(String str) throws IOException

This method encodes a string using a modified UTF-8 format and writes it to the output stream.

str is the string to be written.

IOException if an I/O error occurs.

FilenameFilter

Object

See also: File

The FilenameFilter interface describes a filename filter used to filter directory listings. Filename filters are used by the list method defined in the File class, as well as the AWT's FileDialog component; here is the definition for the interface:

public interface java.io.FilenameFilter {
// Methods
public abstract boolean accept(File dir, String name);
}

accept

FilenameFilter

public abstract boolean accept(File dir, String name)

This method determines whether a file should be included in a directory listing.

dir is the directory in which the file is located.

name is the filename.

true if the file should be included in the directory list; false otherwise.

BufferedInputStream

FilterInputStream

See also: BufferedOutputStream.

This class implements a buffered input stream, which allows you to read data from a stream without causing a call to the underlying system for each byte read. This is done by reading blocks of data into a buffer, where the data is readily accessible, independent of the underlying stream. Subsequent reads are much faster since they read from the buffer rather than the underlying input stream. Here is the definition for the BufferedInputStream class:

public class java.io.BufferedInputStream extends java.io.FilterInputStream
{
   // Member Variables
   protected byte buf[];
   protected int count;
   protected int marklimit;
   protected int markpos;
   protected int pos;

   // Constructors
   public BufferedInputStream(InputStream in);
   public BufferedInputStream(InputStream in, int size);

   // Methods
   public int available();
   public void mark(int readlimit);
   public boolean markSupported();
   public int read();
   public int read(byte b[], int off, int len);
   public void reset();
   public long skip(long n);
}

Member Variables

Following are the member variables defined in BufferedInputStream:

protected byte buf[]

This is the buffer where data is stored.

protected int count

This is the number of bytes of data currently in the buffer.

protected int marklimit

This is the maximum number of bytes that can be read before the marked position (markpos) is invalidated.

protected int markpos

This is the position in the buffer of the current mark, used to return to a particular location in the buffer with the mark and reset methods. The mark position is set to -1 if there is no current mark.

protected int pos

This is the current read position in the buffer.

BufferedInputStream

BufferedInputStream

public BufferedInputStream(InputStream in)

This constructor creates a new buffered input stream, with a default buffer size of 512 bytes, to read data from the in input stream.

in is the input stream to read data from.

BufferedInputStream

BufferedInputStream

public BufferedInputStream(InputStream in, int size)

This constructor creates a new buffered input stream, with a buffer size of size bytes, to read data from the in input stream.

in is the input stream to read data from.

size is the buffer size.

Available

BufferedInputStream

public int available() throws IOException

This method determines the number of bytes that can be read from the input stream without blocking. That number is calculated by adding the number of free bytes in the buffer and the number of bytes available in the input stream.

the number of available bytes.

IOException if an I/O error occurs.

available in class FilterInputStream.

Mark

BufferedInputStream

public void mark(int readlimit)

This method marks the current read position in the input stream. The reset method can be used to reset the read position to this mark; subsequent reads will read data beginning at the mark position. The mark position is invalidated after readlimit bytes have been read.

readlimit is the maximum number of bytes that can be read before the mark position becomes invalid.

mark in class FilterInputStream.

MarkSupported

BufferedInputStream

public boolean markSupported()

This method determines whether the input stream supports the mark and reset methods.

true if the mark and reset methods are supported; false otherwise.

markSupported in class FilterInputStream.

Read

BufferedInputStream

public int read() throws IOException

This method reads a byte value from the buffered input stream, blocking until the byte is read.

an integer representing the byte value read, or -1 if the end of the stream is reached.

IOException if an I/O error occurs.

read in class FilterInputStream.

Read

BufferedInputStream

public int read(byte b[], int off, int len) throws IOException
This method reads up to len bytes from the buffered input stream into the byte array b beginning off bytes into the array, blocking until all bytes are read.

b is the byte array into which the data is read.

off is the starting offset into the array for the data to be written to.

len is the maximum number of bytes to read.

the actual number of bytes read, or -1 if the end of the stream is reached.

IOException if an I/O error occurs.

read in class FilterInputStream.

Reset

BufferedInputStream

public void reset() throws IOException

This method resets the read position in the input stream to the current mark position, as set by the mark method.

IOException if the stream has not been marked or if the mark is invalid.

reset in class FilterInputStream.

Skip

BufferedInputStream

public long skip(long n) throws IOException

This method skips n bytes of data in the input stream.

n is the number of bytes to skip.

the actual number of bytes skipped.

IOException if an I/O error occurs.

skip in class FilterInputStream.

BufferedOutputStream

FilterOutputStream

See also: BufferedInputStream.

This class implements a buffered output stream, which enables you to write data to a stream without causing a call to the underlying system for each byte written. This is done by writing blocks of data into a buffer rather than directly to the underlying output stream. The buffer is then written to the underlying output stream when the buffer fills up or is flushed or when the stream is closed. This is the definition for the BufferedOutputStream class:

public class java.io.BufferedOutputStream extends java.io.FilterOutputStream {
   // Member Variables
   protected byte buf[];
   protected int count;

   // Constructors
   public BufferedOutputStream(OutputStream out);
   public BufferedOutputStream(OutputStream out, int size);

   // Methods
   public void flush();
   public void write(byte b[], int off, int len);
   public void write(int b);
}

Member Variables

Following are the member variables defined in BufferedOutputStream:

protected byte buf[]

This is the buffer where data is stored.

protected int count

This is the number of bytes of data currently in the buffer.

BufferedOutputStream

BufferedOutputStream

public BufferedOutputStream(OutputStream out)

This constructor creates a new buffered output stream, with a default buffer size of 512 bytes, to write data to the out output stream.

out is the output stream to write data to.

BufferedOutputStream

BufferedOutputStream

public BufferedOutputStream(OutputStream out, int size)

This constructor creates a new buffered output stream, with a buffer size of size bytes, to write data to the out output stream.

out is the output stream to write data to.

size is the buffer size.

Flush

BufferedOutputStream

public void flush() throws IOException

This method flushes the output stream, resulting in any buffered data being written to the underlying output stream.

IOException if an I/O error occurs.

flush in class FilterOutputStream.

Write

BufferedOutputStream

public void write(byte b[], int off, int len) throws IOException

This method writes len bytes to the buffered output stream from the byte array b beginning off bytes into the array.

b is the byte array from which the data is written.

off is the starting offset into the array for the data to be read from.

len is the number of bytes to write.

IOException if an I/O error occurs.

write in class FilterOutputStream.

Write

BufferedOutputStream

public void write(int b) throws IOException

This method writes a byte value to the buffered output stream.

b is the byte value to be written.

IOException if an I/O error occurs.

write in class FilterOutputStream.

ByteArrayInputStream

InputStream

See also: ByteArrayOutputStream.

The ByteArrayInputStream class implements an input stream whose data is read from an array of bytes; here is the definition for the class:

public class java.io.ByteArrayInputStream extends java.io.InputStream {
   // Member Variables
   protected byte buf[];
   protected int count;
   protected int pos;

   // Constructors
   public ByteArrayInputStream(byte b[]);
   public ByteArrayInputStream(byte b[], int off, int len);

  // Methods
  public int available();
  public int read();
  public int read(byte b[], int off, int len);
  public void reset();
  public long skip(long n);
}

Member Variables

Following are the member variables defined in ByteArrayInputStream:

protected byte buf[]

This is the buffer where data is stored.

protected int count

This is the number of bytes of data currently in the buffer.

protected int pos

This is the current read position in the buffer.

ByteArrayInputStream

ByteArrayInputStream

public ByteArrayInputStream(byte b[])

This constructor creates a new input stream from the byte array b. Note that the byte array is not copied to create the stream.

b is the byte array from which the data is read.

ByteArrayInputStream

ByteArrayInputStream

public ByteArrayInputStream(byte b[], int off, int len)

This constructor creates a new input stream of size len from the byte array b beginning off bytes into the array. Note that the byte array is not copied to create the stream.

b is the byte array from which the data is read.

off is the starting offset into the array for the data to be read from.

len is the maximum number of bytes to read.

Available

ByteArrayInputStream

public int available()

This method determines the number of bytes that can be read from the input stream.

the number of available bytes.

available in class InputStream.

Read

ByteArrayInputStream

public int read()

This method reads a byte value from the input stream.

an integer representing the byte value read, or -1 if the end of the stream is reached.

read in class InputStream.

Read

ByteArrayInputStream

public int read(byte b[], int off, int len)

This method reads up to len bytes from the input stream into the byte array b beginning off bytes into the array.

b is the byte array into which the data is read.

off is the starting offset into the array for the data to be written to.

len is the maximum number of bytes to read.

the actual number of bytes read, or -1 if the end of the stream is reached.

read in class InputStream.

Reset

ByteArrayInputStream

public void reset()

This method resets the read position to the beginning of the input stream.

reset in class InputStream.

Skip

ByteArrayInputStream

public long skip(long n)

This method skips n bytes of data in the input stream.

n is the number of bytes to skip.

the actual number of bytes skipped.

skip in class InputStream.

ByteArrayOutputStream

OutputStream

See also: ByteArrayInputStream.

The ByteArrayOutputStream class implements an output stream whose data is written to an array of bytes. The byte array automatically grows as data is written to it. Here is the definition for the class:

public class java.io.ByteArrayOutputStream extends java.io.OutputStream {
  // Member Variables
  protected byte buf[];
  protected int count;

  // Constructors
  public ByteArrayOutputStream();
  public ByteArrayOutputStream(int size);

  // Methods
  public void reset();
  public int size();
  public byte[] toByteArray();
  public String toString();
  public String toString(int hibyte);
  public void write(byte b[], int off, int len);
  public void write(int b);
  public void writeTo(OutputStream out);
}

Member Variables

Following are the member variables defined in ByteArrayOutputStream:

protected byte buf[]

This is the buffer where data is stored.

protected int count

This is the number of bytes of data currently in the buffer.

ByteArrayOutputStream

ByteArrayOutputStream

public ByteArrayOutputStream()

This constructor creates a new output stream with a default buffer size of 32 bytes. The size of the buffer automatically grows as data is written to it.

ByteArrayOutputStream

ByteArrayOutputStream

public ByteArrayOutputStream(int size)

This constructor creates a new output stream with an initial size of size bytes. The size of the buffer automatically grows as data is written to it.

size is the initial size of the buffer.

Reset

ByteArrayOutputStream

public void reset()

This method resets the contents of the underlying byte array by setting the count member variable to zero, resulting in the accumulated data being discarded.

Size

ByteArrayOutputStream

public int size()

This method returns the current size of the buffer, which is stored in the count member variable.

the current size of the buffer.

ToByteArray

ByteArrayOutputStream

public byte[] toByteArray()

This method creates a new byte array containing the data currently stored in the underlying byte array associated with the output stream.

a byte array containing the current data stored in the output stream.

ToString

ByteArrayOutputStream

public String toString()

This method creates a new string containing the data currently stored in the underlying byte array associated with the output stream.

a string containing the current data stored in the output stream.

toString in class Object.

ToString

ByteArrayOutputStream

public String toString(int hibyte)

This method creates a new string containing the data currently stored in the underlying byte array associated with the output stream, with the top 8 bits of each string character set to hibyte.

hibyte is the high byte value for each character.

a string containing the current data stored in the output stream, with the high byte of each character set to hibyte.

Write

ByteArrayOutputStream

public void write(byte b[], int off, int len)

This method writes len bytes to the output stream from the byte array b beginning off bytes into the array.

b is the byte array from which the data is written.

off is the starting offset into the array for the data to be read from.

len is the number of bytes to write.

write in class OutputStream.

Write

ByteArrayOutputStream

public void write(int b)

This method writes a byte value to the output stream.

b is the byte value to be written.

write in class OutputStream.

WriteTo

ByteArrayOutputStream

public void writeTo(OutputStream out) throws IOException

This method writes the contents of the underlying byte array to another output

stream.

out is the output stream to write to.

IOException if an I/O error occurs.

DataInputStream

FilterInputStream

DataInput

See also: DataOutputStream.

The DataInputStream class implements an input stream that can read Java primitive data types in a platform-independent manner. Here is the definition for the class:

public class java.io.DataInputStream extends java.io.FilterInputStream
  implements java.io.DataInput {
  // Constructors
  public DataInputStream(InputStream in);

  // Methods
  public final int read(byte b[]);
  public final int read(byte b[], int off, int len);
  public final boolean readBoolean();
  public final byte readByte();
  public final char readChar();
  public final double readDouble();
  public final float readFloat();
  public final void readFully(byte b[]);
  public final void readFully(byte b[], int off, int len);
  public final int readInt();
  public final String readLine();
  public final long readLong();
  public final short readShort();
  public final int readUnsignedByte();
  public final int readUnsignedShort();
  public final String readUTF();
  public final static String readUTF(DataInput in);
  public final int skipBytes(int n);
}

DataInputStream

DataInputStream

public DataInputStream(InputStream in)

This method creates a new data input stream to read data from the in input stream.

in is the input stream to read data from.

Read

DataInputStream

public final int read(byte b[]) throws IOException

This method reads up to b.length bytes from the data input stream into the byte array b, blocking until all bytes are read.

b is the byte array into which the data is read.

the actual number of bytes read, or -1 if the end of the stream is reached.

IOException if an I/O error occurs.

read in class FilterInputStream.

Read

DataInputStream

public final int read(byte b[], int off, int len) throws IOException

This method reads up to len bytes from the data input stream into the byte array b beginning off bytes into the array, blocking until all bytes are read.

b is the byte array into which the data is read.

off is the starting offset into the array for the data to be written to.

len is the maximum number of bytes to read.

the actual number of bytes read, or -1 if the end of the stream is reached.

IOException if an I/O error occurs.

read in class FilterInputStream.

ReadBoolean

DataInputStream

public final boolean readBoolean() throws IOException

This method reads a Boolean value (byte) from the data input stream, blocking until the byte is read. A value of 0 is interpreted as false, and all other values are interpreted as true.

the Boolean value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadByte

DataInputStream

public final byte readByte() throws IOException

This method reads a signed byte (8-bit) value from the data input stream, blocking until the byte is read.

the byte value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadChar

DataInputStream

public final char readChar() throws IOException

This method reads a character (16-bit) value from the data input stream, blocking until both bytes are read.

the character value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadDouble

DataInputStream

public final double readDouble() throws IOException

This method reads a double (64-bit) value from the data input stream, blocking until all eight bytes are read.

the double value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadFloat

DataInputStream

public final float readFloat() throws IOException

This method reads a float (32-bit) value from the data input stream, blocking until all four bytes are read.

the float value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadFully DataInputStream

public final void readFully(byte b[]) throws IOException

This method reads up to b.length bytes from the data input stream into the byte array b, blocking until all bytes are read.

b is the byte array into which the data is read.

EOFException if the end of the stream is reached before reading the specified number of bytes.

IOException if an I/O error occurs.

ReadFully

ReadFully


public final void readFully(byte b[], int off, int len) throws IOException

This method reads up to len bytes from the data input stream into the byte array b beginning off bytes into the array, blocking until all bytes are read.

b is the byte array into which the data is read.

off is the starting offset into the array for the data to be written to.

len is the maximum number of bytes to read.

EOFException if the end of the stream is reached before reading the specified number of bytes.

IOException if an I/O error occurs.

ReadInt

DataInputStream

public final int readInt() throws IOException

This method reads an integer (32-bit) value from the data input stream, blocking until all four bytes are read.

the integer value read.

EOFException if the end of the stream is reached before reading the value.

IOException if an I/O error occurs.

ReadLine

DataInputStream

public final String readLine() throws IOException

This method reads a line of text from the data input stream, blocking until either a newline character (\n) or a carriage return character (\r) is read.

a string containing the line of text read.

EOFException if the end of the stream is reached before reading the line of text.