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.

IOException if an I/O error occurs.

ReadLong

DataInputStream

public final long readLong() throws IOException

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

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

DataInputStream

public final short readShort() throws IOException

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

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

DataInputStream

public final int readUnsignedByte() throws IOException

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

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

DataInputStream

public final int readUnsignedShort() throws IOException

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

the unsigned short value read.

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

IOException if an I/O error occurs.

ReadUTF

DataInputStream

public final String readUTF() throws IOException

This method reads a string that has been encoded using a modified UTF-8 format from the data input stream, blocking until all bytes are read.

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.

ReadUTF

DataInputStream

public final static String readUTF(DataInput in) throws IOException

This method reads a string from the in data input stream that has been encoded using a modified UTF-8 format, blocking until all bytes are read.

in is the data input stream to read the string from.

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

DataInputStream

public final int skipBytes(int n) throws IOException

This method skips n bytes of data in the data 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.

DataOutputStream

FilterOutputStream

DataOutput

See also: DataInputStream.

The DataOutputStream class implements an output stream that can write Java primitive data types in a platform-independent manner; this is the definition for the class:

public class java.io.DataOutputStream extends java.io.FilterOutputStream
  implements java.io.DataOutput {
  // Member Variables
  protected int written;

  // Constructors
  public DataOutputStream(OutputStream out);

  // Methods
  public void flush();
  public final int size();
  public void write(byte b[], int off, int len);
  public void write(int b);
  public final void writeBoolean(boolean v);
  public final void writeByte(int v);
  public final void writeBytes(String s);
  public final void writeChar(int v);
  public final void writeChars(String s);
  public final void writeDouble(double v);
  public final void writeFloat(float v);
  public final void writeInt(int v);
  public final void writeLong(long v);
  public final void writeShort(int v);
  public final void writeUTF(String str);
}

Member Variables

Following are the member variables defined in DataOutputStream:

protected int written

This is the number of bytes written to the output stream so far.

DataOutputStream

DataOutputStream

public DataOutputStream(OutputStream out)

This method creates a new data output stream to write data to the out output stream.

out is the output stream to write data to.

Flush

DataOutputStream

public void flush() throws IOException

This method flushes the data 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.

Size

DataOutputStream

public final int size()

This method returns the number of bytes written to the data output stream thus far, which is stored in the written member variable.

the number of bytes written to the data output stream so far.

Write

DataOutputStream

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

This method writes len bytes to the data 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

DataOutputStream

public void write(int b) throws IOException

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

b is the byte value to be written.

IOException if an I/O error occurs.

write in class FilterOutputStream.

WriteBoolean

DataOutputStream

public final void writeBoolean(boolean v) throws IOException

This method writes a Boolean value to the data 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

DataOutputStream

public final void writeByte(int v) throws IOException

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

v is the byte value to be written.

IOException if an I/O error occurs.

WriteBytes

DataOutputStream

public final void writeBytes(String s) throws IOException

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

s is the string to be written as bytes.

IOException if an I/O error occurs.

WriteChar

DataOutputStream

public final void writeChar(int v) throws IOException

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

v is the character value to be written.

IOException if an I/O error occurs.

WriteChars

DataOutputStream

public final void writeChars(String s) throws IOException

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

s is the string to be written as characters.

IOException if an I/O error occurs.

WriteDouble

DataOutputStream

public final void writeDouble(double v) throws IOException

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

v is the double value to be written.

IOException if an I/O error occurs.

WriteFloat

DataOutputStream

public final void writeFloat(float v) throws IOException

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

v is the float value to be written.

IOException if an I/O error occurs.

WriteInt

DataOutputStream

public final void writeInt(int v) throws IOException

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

v is the integer value to be written.

IOException if an I/O error occurs.

WriteLong

DataOutputStream

public final void writeLong(long v) throws IOException

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

v is the long value to be written.

IOException if an I/O error occurs.

WriteShort

DataOutputStream

public final void writeShort(int v) throws IOException

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

v is the short value to be written.

IOException if an I/O error occurs.

WriteUTF

DataOutputStream

public final void writeUTF(String str) throws IOException

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

str is the string to be written.

IOException if an I/O error occurs.

File

Object

See also: FileDescriptor.

The File class implements a filename in a platform-independent manner; it gives you the functionality needed to work with filenames and directories without having to deal with the complexities associated with filenames on a particular platform. Here is the class definition:

public class java.io.File extends java.lang.Object {
  // Member Variables
  public final static String pathSeparator;
  public final static char pathSeparatorChar;
  public final static String separator;
  public final static char separatorChar;

  // Constructors
  public File(File dir, String name);
  public File(String path);
  public File(String path, String name);

  // Methods
  public boolean canRead();
  public boolean canWrite();
  public boolean delete();
  public boolean equals(Object obj);
  public boolean exists();
  public String getAbsolutePath();
  public String getName();
  public String getParent();
  public String getPath();
  public int hashCode();
  public boolean isAbsolute();
  public boolean isDirectory();
  public boolean isFile();
  public long lastModified();
  public long length();
  public String[] list();
  public String[] list(FilenameFilter filter);
  public boolean mkdir();
  public boolean mkdirs();
  public boolean renameTo(File dest);
  public String toString();
}

Member Variables

Following are the member variables defined in File:

public final static String pathSeparator

This is the platform-specific path separator string.

public final static char pathSeparatorChar

This is the platform-specific path separator character, which separates filenames in a path list.

public final static String separator

This is the platform-specific file separator string.

public final static char separatorChar

This is the platform-specific file separator character, which separates the file and directory components in a filename.

File

File

public File(File dir, String name)

This constructor creates the filename of an underlying file based on the specified directory and filename. If no directory is specified in the dir argument, the constructor assumes the file is in the current directory.

dir is the directory where the file is located.

name is the filename.

File

File

public File(String path)

This constructor creates the filename of an underlying file based on the specified file path.

path is the file path.

NullPointerException if the file path is null.

File

File

public File(String path, String name)

This constructor creates the filename of an underlying file based on the specified path and filename.

path is the path where the file is located.

name is the filename.

CanRead

File

public boolean canRead()

This method determines whether the underlying file can be read from. In other words, if the file is readable, canRead determines whether the file exists.

true if the file can be read from; false otherwise.

SecurityException if the application doesn't have read access to the file.

CanWrite

File

public boolean canWrite()

This method determines whether the underlying file can be written to. In other words, if the file is writeable, canWrite determines whether the file exists.

true if the file can be written to; false otherwise.

SecurityException if the application doesn't have write access to the file.

Delete

File

public boolean delete()

This method deletes the underlying file.

true if the file is deleted; false otherwise.

SecurityException if the application doesn't have access to delete the file.

Equals

File

public boolean equals(Object obj)

This method compares the path name of the obj File object to the path name of the underlying file.

obj is the object to compare with.

true if the path names are equal; false otherwise.

equals in class Object.

exists

File

public boolean exists()

This method determines whether the underlying file exists by opening it for reading and then closing it.

true if the file exists; false otherwise.

SecurityException if the application doesn't have read access to the file.

getAbsolutePath

File

public String getAbsolutePath()

This method determines the platform-specific absolute path name of the underlying file.

the absolute path name of the file.

getName

File

public String getName()

This method determines the filename of the underlying file, which doesn't include any path information.

the filename of the file.

getParent

File

public String getParent()

This method determines the parent directory of the underlying file, which is the immediate directory where the file is located.

the parent directory of the file, or null if the file is located in the root directory.

getPath

File

public String getPath()

This method determines the path name of the underlying file.

the path name of the file.

hashCode

File

public int hashCode()

This method calculates a hash code for the underlying file.

a hash code for the file.

hashCode in class Object.

isAbsolute

File

public boolean isAbsolute()

This method determines whether this object represents an absolute path name for the underlying file. Note that absolute path names are platform specific.

true if the path name for the file is absolute; false otherwise.

isDirectory

File

public boolean isDirectory()

This method determines whether the underlying file is actually a directory.

true if the file is actually a directory; false otherwise.

SecurityException if the application doesn't have read access to the file.

isFile

File

public boolean isFile()

This method determines whether the underlying file is a normal file-that is, not a directory.

true if the file is a normal file; false otherwise.

SecurityException if the application doesn't have read access to the file.

lastModified

File

public long lastModified()

This method determines the last modification time of the underlying file. Note that this time is system specific and is not absolute; in other words, use the time only to compare against other times retrieved by using this method.

the last modification time of the file, or 0 if the file doesn't exist.

SecurityException if the application doesn't have read access to the file.

length

File

public long length()

This method determines the length in bytes of the underlying file.

the length of the file in bytes.

SecurityException if the application doesn't have read access to the file.

list

File

public String[] list()

This method builds a list of the filenames in the directory represented by this object. Note that the underlying file must actually be a directory for this method to work.

an array containing the filenames located in the directory.

SecurityException if the application doesn't have read access to the file.

list

File

public String[] list(FilenameFilter filter)

This method builds a list, using the specified filename filter, of the filenames in the directory represented by this object. Note that the underlying file must actually be a directory for this method to work.

filter is the filename filter used to select the filenames.

an array containing the filtered filenames in the directory.

SecurityException if the application doesn't have read access to the file.

mkdir

File

public boolean mkdir()

This method creates a directory based on the path name specified by this object.

true if the directory is created; false otherwise.

SecurityException if the application doesn't have write access to the file.

mkdirs

File

public boolean mkdirs()

This method creates a directory based on the path name specified by this object, including all necessary parent directories.

true if the directory (or directories) is created; false otherwise.

SecurityException if the application doesn't have write access to the file.

renameTo

File

public boolean renameTo(File dest)

This method renames the underlying file to the filename specified by the dest file object.

dest is the new filename.

true if the file is renamed; false otherwise.

SecurityException if the application doesn't have write access to both the underlying file and the file represented by the dest file object.

toString

File

public String toString()

This method determines a string representation of the path name for the underlying file.

a string representing the path name of the file.

toString in class Object.

FileDescriptor

Object

See also: File.

The FileDescriptor class implements a handle to a platform-specific file or socket structure. FileDescriptor objects are primarily used internally by the Java system and are never created by an application directly. Here is the class definition:

public final class java.io.FileDescriptor extends java.lang.Object {
  // Member Variables
  public final static FileDescriptor err;
  public final static FileDescriptor in;
  public final static FileDescriptor out;

  // Constructors
  public FileDescriptor();

  // Methods
  public boolean valid();
}

Member Variables

Following are the member variables defined in FileDescriptor:

public final static FileDescriptor err

This is a handle to the standard error stream.

public final static FileDescriptor in

This is a handle to the standard input stream.

public final static FileDescriptor out

This is a handle to the standard output stream.

FileDescriptor

FileDescriptor

public FileDescriptor()

This constructor creates a default FileDescriptor object.

valid

FileDescriptor

public boolean valid()

This method determines whether this object represents a valid open file or socket.

true if the underlying file or socket is valid; false otherwise.

FileInputStream

InputStream

See also: FileOutputStream.

The FileInputStream class implements an input stream for reading data from a file or file descriptor; this is the class definition:

public class java.io.FileInputStream extends java.io.InputStream
{
  // Constructors
  public FileInputStream(File file);
  public FileInputStream(FileDescriptor fdObj);
  public FileInputStream(String name);

  // Methods
  public int available();
  public void close();
  protected void finalize();
  public final FileDescriptor getFD();
  public int read();
  public int read(byte b[]);
  public int read(byte b[], int off, int len);
  public long skip(long n);
}

FileInputStream

FileInputStream

public FileInputStream(File file) throws FileNotFoundException

This constructor creates a file input stream to read data from the specified file.

file is the file to be opened for reading.

FileNotFoundException if the file is not found.

SecurityException if the application doesn't have read access to the file.

FileInputStream

FileInputStream

public FileInputStream(FileDescriptor fdObj)

This constructor creates a file input stream to read data from the file represented by the specified file descriptor.

fdObj is the file descriptor representing the file to be opened for reading.

SecurityException if the application doesn't have read access to the file.

FileInputStream

FileInputStream

public FileInputStream(String name) throws FileNotFoundException

This constructor creates a file input stream to read data from the file with the specified filename.

name is the filename of the file to be opened for reading.

FileNotFoundException if the file is not found.

SecurityException if the application doesn't have read access to the file.

available

FileInputStream

public int available() throws IOException

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

the number of available bytes.

IOException if an I/O error occurs.

available in class InputStream.

close

FileInputStream

public void close() throws IOException

This method closes the file input stream, releasing any resources associated with the stream.

IOException if an I/O error occurs.

close in class InputStream.

finalize

FileInputStream

protected void finalize() throws IOException

This method makes sure the close method is called when the file input stream is cleaned up by the Java garbage collector.

IOException if an I/O error occurs.

finalize in class Object.

getFD

FileInputStream

public final FileDescriptor getFD() throws IOException

This method determines the file descriptor associated with the file input stream.

the file descriptor associated with the stream.

IOException if an I/O error occurs.

read

FileInputStream

public int read() throws IOException

This method reads a byte value from the file 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 InputStream.

read

FileInputStream

public int read(byte b[]) throws IOException

This method reads up to b.length bytes from the file 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 InputStream.

read

FileInputStream

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

This method reads up to len bytes from the file 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 InputStream.

skip

FileInputStream

public long skip(long n) throws IOException

This method skips n bytes of data in the file 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 InputStream.

FileOutputStream

OutputStream

See also: FileInputStream.

The FileOutputStream class implements an output stream for writing data to a file or file descriptor; this is the class definition:

public class java.io.FileOutputStream extends java.io.OutputStream
{
  // Constructors
  public FileOutputStream(File file);
  public FileOutputStream(FileDescriptor fdObj);
  public FileOutputStream(String name);

  // Methods
  public void close();
  protected void finalize();
  public final FileDescriptor getFD();
  public void write(byte b[]);
  public void write(byte b[], int off, int len);
  public void write(int b);
}

FileOutputStream

FileOutputStream

public FileOutputStream(File file) throws IOException

This constructor creates a file output stream to write data to the specified file.

file is the file to be opened for writing.

FileNotFoundException if the file could not be opened for writing.

SecurityException if the application doesn't have write access to the file.

FileOutputStream

FileOutputStream

public FileOutputStream(FileDescriptor fdObj)

This constructor creates a file output stream to write data to the file represented by the specified file descriptor.

fdObj is the file descriptor representing the file to be opened for writing.

SecurityException if the application doesn't have write access to the file.

FileOutputStream

FileOutputStream

public FileOutputStream(String name) throws IOException

This constructor creates a file output stream to write data to the file with the specified filename.

name is the filename of the file to be opened for writing.

FileNotFoundException if the file is not found.

SecurityException if the application doesn't have read access to the file.

close

FileOutputStream

public void close() throws IOException

This method closes the file output stream, releasing any resources associated with it.

IOException if an I/O error occurs.

close in class OutputStream.

finalize

FileOutputStream

protected void finalize() throws IOException

This method makes sure the close method is called when the file output stream is cleaned up by the Java garbage collector.

IOException if an I/O error occurs.

finalize in class Object.

getFD

FileOutputStream

public final FileDescriptor getFD() throws IOException

This method determines the file descriptor associated with the file output stream.

the file descriptor associated with the stream.

IOException if an I/O error occurs.

write

FileOutputStream

public void write(byte b[]) throws IOException

This method writes b.length bytes to the file output stream from the byte array b.

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

IOException if an I/O error occurs.

write in class OutputStream.

write

FileOutputStream

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

This method writes len bytes to the file 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 OutputStream.

write

FileOutputStream

public void write(int b) throws IOException

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

b is the byte value to be written.

IOException if an I/O error occurs.

write in class OutputStream.

FilterInputStream

InputStream

See also: FilterOutputStream.

The FilterInputStream class defines an input stream filter used to filter data on an underlying input stream. Most of the methods defined in this class merely call corresponding methods in the underlying input stream, and you simply override appropriate methods to supply the
filtering functionality. FilterInputStream is the basis for all other input stream filter implementations. Derived filtered input streams can be linked for complex filtering operations; here is the class definition:

public class java.io.FilterInputStream extends java.io.InputStream {
  // Member Variables
  protected InputStream in;

  // Constructors
  protected FilterInputStream(InputStream in);

  // Methods
  public int available();
  public void close();
  public void mark(int readlimit);
  public boolean markSupported();
  public int read();
  public int read(byte b[]);
  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 FilterInputStream:

protected InputStream in

This is the underlying input stream being filtered.

FilterInputStream

FilterInputStream

protected FilterInputStream(InputStream in)

This constructor creates a filtered input stream based on the specified underlying input stream.

in is the input stream to be filtered.

available

FilterInputStream

public int available() throws IOException

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

the number of available bytes.

IOException if an I/O error occurs.

available in class InputStream.

close

FilterInputStream

public void close() throws IOException

This method closes the filtered input stream, releasing any resources associated with it.

IOException if an I/O error occurs.

close in class InputStream.

mark

FilterInputStream

public void mark(int readlimit)

This method marks the current read position in the filtered 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 InputStream.

markSupported

FilterInputStream

public boolean markSupported()

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

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

markSupported in class InputStream.

read

FilterInputStream

public int read() throws IOException

This method reads a byte value from the filtered 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 InputStream.

read

FilterInputStream

public int read(byte b[]) throws IOException

This method reads up to b.length bytes from the filtered 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 InputStream.

read

FilterInputStream

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

This method reads up to len bytes from the filtered 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 InputStream.

reset

FilterInputStream

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 InputStream.

skip

FilterInputStream

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 InputStream.

FilterOutputStream

OutputStream

See also: FilterOutputStream.

The FilterOutputStream class defines an output stream filter used to filter data on an underlying output stream. Most of the methods defined in this class merely call corresponding methods in the underlying output stream, and you simply override appropriate methods to supply the filtering functionality. FilterOutputStream is the basis for all other output stream filter implementations. Derived filtered output streams can be linked for complex filtering operations; this is the class definition:

public class java.io.FilterOutputStream extends java.io.OutputStream {
  // Member Variables
  protected OutputStream out;

  // Constructors
  public FilterOutputStream(OutputStream  out);

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

Member Variables

Following are the member variables defined in FilterOutputStream:

protected OutputStream out

This is the underlying output stream being filtered.

FilterOutputStream

FilterOutputStream

public FilterOutputStream(OutputStream out)

This constructor creates a filtered output stream based on the specified underlying output stream.

out is the output stream to be filtered.

close

FilterOutputStream

public void close() throws IOException

This method closes the filtered output stream, releasing any resources associated with it.

IOException if an I/O error occurs.

close in class OutputStream.

flush

FilterOutputStream

public void flush() throws IOException

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

IOException if an I/O error occurs.

flush in class OutputStream.

write

FilterOutputStream

public void write(byte b[]) throws IOException

This method writes b.length bytes to the filtered output stream from the byte array b.

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

IOException if an I/O error occurs.

write in class OutputStream.

write

FilterOutputStream

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

This method writes len bytes to the filtered 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 in class OutputStream.

write

FilterOutputStream

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 OutputStream.

InputStream

Object

See also: OutputStream.

The InputStream class is an abstract class representing an input stream of bytes; all input streams are based on this class. Here is the InputStream definition:

public abstract class java.io.InputStream extends java.lang.Object {
  // Constructors
  public InputStream();

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

InputStream

InputStream

public InputStream()

This constructor creates a default input stream.

available

InputStream

public int available() throws IOException

This method determines the number of bytes that can be read from the input stream without blocking. This method should be overridden in all subclasses because it returns 0 in InputStream.

the number of available bytes.

IOException if an I/O error occurs.

close

InputStream

public void close() throws IOException

This method closes the input stream, releasing any resources associated with it. This method should usually be overridden in subclasses, since it does nothing in InputStream.

IOException if an I/O error occurs.

mark

InputStream

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. This method should usually be overridden in subclasses because it does nothing in InputStream.

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

markSupported

InputStream

public boolean markSupported()

This method determines whether the input stream supports the mark and reset methods. This method should usually be overridden in subclasses, since it always returns false in InputStream.

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

read

InputStream

public abstract int read() throws IOException

This method reads a byte value from the input stream, blocking until the byte is read. This method must be overridden in all subclasses because it's defined as abstract in InputStream.

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

InputStream

public int read(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. This method actually calls the three-parameter version of read, passing b, 0, and b.length as the parameters.

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

InputStream

public int read(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. This method actually reads each byte by calling the read method that takes no parameters. Subclasses should offer a more efficient implementation of this method, one that doesn't rely on the other read method, if possible.

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.

reset

InputStream

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. This method should be overridden in subclasses requiring mark/reset functionality, since it always throws an IOException in InputStream; this happens because input streams don't support, by default, mark/reset functionality.

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

skip

InputStream

public long skip(long n) throws IOException

This method skips n bytes of data in the input stream. This method should usually be overridden with a more efficient version in subclasses because it reads skipped data into a temporary byte array in InputStream.

n is the number of bytes to skip.

the actual number of bytes skipped.

IOException if an I/O error occurs.

LineNumberInputStream

FilterInputStream

The LineNumberInputStream class implements an input stream that keeps track of how many lines have passed through the stream. A line is defined as a sequence of bytes followed by either a carriage return character (\r), a newline character (\n), or a carriage return character immediately followed by a newline character. In all three cases, the newline is interpreted as a single character. Here is the class definition:

public class java.io.LineNumberInputStream extends java.io.FilterInputStream {
  // Constructors
  public LineNumberInputStream(InputStream  in);

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

LineNumberInputStream

LineNumberInputStream

public LineNumberInputStream(InputStream in)

This constructor creates a line number input stream that counts lines based on the specified input stream.

in is the input stream to count lines from.

available

LineNumberInputStream

public int available() throws IOException

This method determines the number of bytes that can be read from the input stream without blocking. Note that this number could be as small as half that of the underlying stream, since LineNumberInputStream combines carriage return/newline character pairs into a single newline byte.

the number of available bytes.

available in class FilterInputStream.

getLineNumber

LineNumberInputStream

public int getLineNumber()

This method determines the current line number for the input stream, which is the count of how many lines the stream has processed.

the current line number.

mark

LineNumberInputStream

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. The mark method ensures that the current line number is stored so it isn't invalidated by a subsequent call to reset.

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

mark in class FilterInputStream.

read

LineNumberInputStream

public int read() throws IOException

This method reads a byte value from the 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

LineNumberInputStream

public int read(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.

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

LineNumberInputStream

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. The current line number is reset to the value it held when the mark method was called.

reset in class FilterInputStream.

setLineNumber

LineNumberInputStream

public void setLineNumber(int lineNumber)

This method sets the current line number to the specified line number.

lineNumber is the new line number to be set.

skip

LineNumberInputStream

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.

OutputStream

Object

See also: InputStream.

OutputStream is an abstract class representing an output stream of bytes. All output streams are based on OutputStream; here is its class definition:

public abstract class java.io.OutputStream extends java.lang.Object {
  // Constructors
  public OutputStream();

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

OutputStream

OutputStream

public OutputStream()

This constructor creates a default output stream.

close

OutputStream

public void close() throws IOException

This method closes the output stream, releasing any resources associated with it. This method should usually be overridden in subclasses, since it does nothing in OutputStream.

IOException if an I/O error occurs.

flush

OutputStream

public void flush() throws IOException

This method flushes the output stream, resulting in any buffered data being written to the underlying output stream. It should usually be overridden in subclasses because it does nothing in OutputStream.

IOException if an I/O error occurs.

write

OutputStream

public void write(byte b[]) throws IOException

This method writes b.length bytes to the output stream from the byte array b. This method actually calls the three-parameter version of write, passing b, 0, and b.length as the parameters.

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

IOException if an I/O error occurs.

write

OutputStream

public 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. It actually writes each byte by calling the write method that takes one parameter. Subclasses should offer a more efficient way for this method to work that doesn't rely on the other write method, if possible.

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

OutputStream

public abstract void write(int b) throws IOException

This method writes a byte value to the output stream. This method must be overridden in all subclasses because it's defined as abstract in OutputStream.

b is the byte value to be written.

IOException if an I/O error occurs.

PipedInputStream

InputStream

See also: PipedOutputStream.

This class implements a piped input stream, which acts as the receiving end of a communications pipe. Piped input streams must be connected to a piped output stream to receive data. In other words, a piped output stream must be used to send the data received by a piped input stream. Here is the definition for the PipedInputStream class:

public class java.io.PipedInputStream extends java.io.InputStream {
  // Constructors
  public PipedInputStream();
  public PipedInputStream(PipedOutputStream src);

  // Methods
  public void close();
  public void connect(PipedOutputStream src);
  public int read();
  public int read(byte b[], int off, int len);
}

PipedInputStream

PipedInputStream

public PipedInputStream()

This constructor creates a piped input stream that isn't connected to anything. The stream must be connected to a piped output stream with the connect method before it can be used.

PipedInputStream

PipedInputStream

public PipedInputStream(PipedOutputStream src) throws IOException

This constructor creates a piped input stream connected to the specified piped output stream.

src is the piped output stream to connect to.

IOException if an I/O error occurs.

close

PipedInputStream

public void close() throws IOException

This method closes the piped input stream, releasing any resources associated with it.

IOException if an I/O error occurs.

close in class InputStream.

connect

PipedInputStream

public void connect(PipedOutputStream src) throws IOException

This method connects the input stream to the specified piped output stream.

src is the piped output stream to connect to.

IOException if an I/O error occurs.

read

PipedInputStream

public int read() throws IOException

This method reads a byte value from the piped 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 InputStream.

read

PipedInputStream

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

This method reads up to len bytes from the piped 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 InputStream.

PipedOutputStream

OutputStream

See also: PipedInputStream.

The PipedOutputStream class implements a piped output stream, which acts as the sending end of a communications pipe. Piped output streams must be connected to a piped input stream to send data. In other words, a piped input stream must be used to receive the data sent by a piped output stream. This is the definition for the class:

public class java.io.PipedOutputStream extends java.io.OutputStream {
  // Constructors
  public PipedOutputStream();
  public PipedOutputStream(PipedInputStream snk);

  // Methods
  public void close();
  public void connect(PipedInputStream snk);
  public void write(byte b[], int off, int len);
  public void write(int b);
}

PipedOutputStream

PipedOutputStream

public PipedOutputStream()

This constructor creates a piped output stream that isn't connected to anything. The stream must be connected to a piped input stream with the connect method before it can be used.

PipedOutputStream

PipedOutputStream

public PipedOutputStream(PipedInputStream snk) throws IOException

This constructor creates a piped output stream connected to the specified piped input stream.

snk is the piped input stream to connect to.

IOException if an I/O error occurs.

close

PipedOutputStream

public void close() throws IOException

This method closes the piped output stream, releasing any resources associated with it.

IOException if an I/O error occurs.

close in class OutputStream.

connect

PipedOutputStream

public void connect(PipedInputStream snk) throws IOException

This method connects the output stream to the specified piped input stream.

snk is the piped input stream to connect to.

IOException if an I/O error occurs.

write

PipedOutputStream

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

This method writes len bytes to the piped 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 OutputStream.

write

PipedOutputStream

public void write(int b) throws IOException

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

b is the byte value to be written.

IOException if an I/O error occurs.

write in class OutputStream.

PrintStream

FilterOutputStream

This class implements an output stream that has additional methods for printing basic types of data. You can set up the stream so that it's flushed every time a newline character (\n) is written. Note that only the lower 8 bits of any 16-bit value are printed to the stream. Here is the definition for the PrintStream class:

public class java.io.PrintStream extends java.io.FilterOutputStream {
  // Constructors
  public PrintStream(OutputStream out);
  public PrintStream(OutputStream out, boolean autoflush);

  // Methods
  public boolean checkError();
  public void close();
  public void flush();
  public void print(boolean b);
  public void print(char c);
  public void print(char s[]);
  public void print(double d);
  public void print(float f);
  public void print(int i);
  public void print(long l);
  public void print(Object obj);
  public void print(String s);
  public void println();
  public void println(boolean b);
  public void println(char c);
  public void println(char s[]);
  public void println(double d);
  public void println(float f);
  public void println(int i);
  public void println(long l);
  public void println(Object obj);
  public void println(String s);
  public void write(byte b[], int off, int len);
  public void write(int b);
}

PrintStream

PrintStream

public PrintStream(OutputStream out)

This constructor creates a print stream that writes data to the specified underlying output stream.

out is the output stream to be written to.

PrintStream

PrintStream

public PrintStream(OutputStream out, boolean autoflush)

This constructor creates a print stream that writes data to the specified underlying output stream, with an option of flushing its output each time a newline character (\n) is encountered.

out is the output stream to be written to.

autoflush is a Boolean value specifying whether the stream is flushed when a newline character is encountered.

checkError

PrintStream

public boolean checkError()

This method flushes the underlying output stream and determines whether an error has occurred on the stream. Note that errors are cumulative, meaning that once an error is encountered, checkError will continue to return true on all successive calls.

true if the print stream has ever encountered an error on the underlying output stream; false otherwise.

close

PrintStream

public void close()

This method closes the print stream, releasing any resources associated with the underlying output stream.

close in class FilterOutputStream.

flush

PrintStream

public void flush()

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

flush in class FilterOutputStream.

print

PrintStream

public void print(boolean b)

This method prints the string representation of a Boolean value to the underlying output stream. If the Boolean value is true, the string "true" is printed; otherwise, the string "false" is printed.

b is the Boolean value to be printed.

print

PrintStream

public void print(char c)

This method prints the lower 8 bits of a character value to the underlying output stream.

c is the character value to be printed.

print

PrintStream

public void print(char s[])

This method prints the lower 8 bits of each character value in an array of characters to the underlying output stream.

s is the array of characters to be printed.

print

PrintStream

public void print(double d)

This method prints the string representation of a double value to the underlying output stream. Note that the string representation is the same as that returned by the toString method of the Double class.

d is the double value to be printed.

print

PrintStream

public void print(float f)

This method prints the string representation of a float value to the underlying output stream. Note that the string representation is the same as that returned by the toString method of the Float class.

f is the float value to be printed.

print

PrintStream

public void print(int i)

This method prints the string representation of an integer value to the underlying output stream. Note that the string representation is the same as that returned by the toString method of the Integer class.

i is the integer value to be printed.

print

PrintStream

public void print(long l)

This method prints the string representation of a long value to the underlying output stream. Note that the string representation is the same as that returned by the toString method of the Long class.

l is the long value to be printed.

print

PrintStream

public void print(Object obj)

This method prints the string representation of an object to the underlying output stream. Note that the string representation is the same as that returned by the toString method of the object.

obj is the object to be printed.

print

PrintStream

public void print(String s)

This method prints the lower 8 bits of each character in a string to the underlying output stream. If the string is null, the string "null" is printed.

s is the string to be printed.

println

PrintStream

public void println()

This method prints the newline character (\n) to the underlying output stream.

println

PrintStream

public void println(boolean b)

This method prints the string representation of a Boolean value to the underlying output stream, followed by a newline character (\n). If the Boolean value is true, the string "true" is printed; otherwise, the string "false" is printed.

b is the Boolean value to be printed.

println

PrintStream

public void println(char c)

This method prints the lower 8 bits of a character value to the underlying output stream, followed by a newline character.

c is the character value to be printed.

println

PrintStream

public void println(char s[])

This method prints the lower 8 bits of each character value in an array of characters to the underlying output stream, followed by a newline character.

s is the array of characters to be printed.

println

PrintStream

public void println(double d)

This method prints the string representation of a double value to the underlying output stream, followed by a newline character. Note that the string representation is the same as that returned by the toString method of the Double class.

d is the double value to be printed.

println

PrintStream

public void println(float f)

This method prints the string representation of a float value to the underlying output stream, followed by a newline character. Note that the string representation is the same as that returned by the toString method of the Float class.

f is the float value to be printed.

println

PrintStream

public void println(int i)

This method prints the string representation of an integer value to the underlying output stream, followed by a newline character. Note that the string representation is the same as that returned by the toString method of the Integer class.

i is the integer value to be printed.

println

PrintStream

public void println(long l)

This method prints the string representation of a long value to the underlying output stream, followed by a newline character. Note that the string representation is the same as that returned by the toString method of the Long class.

l is the long value to be printed.

println

PrintStream

public void println(Object obj)

This method prints the string representation of an object to the underlying output stream, followed by a newline character. Note that the string representation is the same as that returned by the toString method of the object.

obj is the object to be printed.

println

PrintStream

public void println(String s)

This method prints the lower 8 bits of each character in a string to the underlying output stream, followed by a newline character. If the string is null, the string "null" is printed.

s is the string to be printed.

write

PrintStream

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

This method writes len bytes to the underlying 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 FilterOutputStream.

write

PrintStream

public void write(int b)

This method writes a byte value to the underlying output stream. The write method of the underlying output stream is actually called to write the byte value. Additionally, if the byte represents the newline character (\n), and autoflush is turned on, the flush method is called.

If an IOException is thrown while writing the byte, the exception is caught and an internal error flag is set; this flag can be checked by calling the checkError method. This technique alleviates having to use a try-catch clause every time you want to print something.

b is the byte value to be written.

IOException if an I/O error occurs.

write in class FilterOutputStream.

PushbackInputStream

FilterInputStream

The PushbackInputStream class implements a input stream filter that provides a one-byte pushback buffer. Using the PushbackInputStream class, an application can push the last byte read back into the stream so it's re-read the next time the read method is called. This function is useful when byte-delimited data is being read; the delimited bytes can be pushed back into the stream so the next read operation will read them. Here is the class definition:

public class java.io.PushbackInputStream extends java.io.FilterInputStream {
  // Member Variables
  protected int pushBack;

  // Constructors
  public PushbackInputStream(InputStream in);

  // Methods
  public int available();
  public boolean markSupported();
  public int read();
  public int read(byte bytes[], int off, int len);
  public void unread(int ch);
}

Member Variables

protected int pushBack

This is the pushback buffer containing the character that was pushed back. A value of -1 indicates that the pushback buffer is empty.

PushbackInputStream

PushbackInputStream

public PushbackInputStream(InputStream in)

This constructor creates a pushback input stream using the specified underlying input stream.

in is the input stream to use the pushback filter on.

available

PushbackInputStream

public int available() throws IOException

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

the number of available bytes.

IOException if an I/O error occurs.

available in class FilterInputStream.

markSupported

PushbackInputStream

public boolean markSupported()

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

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

markSupported in class FilterInputStream.

read

PushbackInputStream

public int read() throws IOException

This method reads a byte value from the pushback input stream, blocking until the byte is read. The read method actually returns the pushback character, if there is one, and calls the underlying input stream's read method, if not.

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

PushbackInputStream

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

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

bytes 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.

unread

PushbackInputStream

public void unread(int ch) throws IOException

This method pushes a character back into the stream so that it's read the next time the read method is called. Note that there can be only one pushback character, meaning that multiple calls to unread without matching calls to read result in an IOException being thrown.

ch is the character to push back into the stream.

IOException if an attempt is made to push back more than one character.

RandomAccessFile

Object

DataOutput, DataInput

The RandomAccessFile class implements a random access file stream, enabling you to both read from and write to random access files. Here is the class definition:

public class java.io.RandomAccessFile extends java.lang.Object
  implements java.io.DataOutput java.io.DataInput {
  // Constructors
  public RandomAccessFile(File file, String mode);
  public RandomAccessFile(String name, String mode);

  // Methods
  public void close();
  public final FileDescriptor getFD();
  public long getFilePointer();
  public long length();
  public int read();
  public int read(byte b[]);
  public 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 void seek(long pos);
  public int skipBytes(int n);
  public void write(byte b[]);
  public void write(byte b[], int off, int len);
  public void write(int b);
  public final void writeBoolean(boolean v);
  public final void writeByte(int v);
  public final void writeBytes(String s);
  public final void writeChar(int v);
  public final void writeChars(String s);
  public final void writeDouble(double v);
  public final void writeFloat(float v);
  public final void writeInt(int v);
  public final void writeLong(long v);
  public final void writeShort(int v);
  public final void writeUTF(String str);
}

RandomAccessFile

RandomAccessFile

public RandomAccessFile(String name, String mode) throws IOException

This constructor creates a random access file stream based on the file with the specified filename and access mode. There are two supported access modes: mode "r" is for read-only files, and mode "rw" is for read/write files.

name is the filename of the file to access.

mode is the access mode.

IOException if an I/O error occurs.

IllegalArgumentException if the access mode is not equal to "r" or "rw".

SecurityException if the access mode is "r" and the application doesn't have read access to the file, or if the access mode is "rw" and the application doesn't have both read and write access to the file.

RandomAccessFile

RandomAccessFile

public RandomAccessFile(File file, String mode) throws IOException

This constructor creates a random access file stream based on the specified file and access mode. There are two supported access modes: mode "r" is for read-only files, and mode "rw" is for read/write files.

file is the file to access.

mode is the access mode.

IOException if an I/O error occurs.

IllegalArgumentException if the access mode is not equal to "r" or "rw".

SecurityException if the access mode is "r" and the application doesn't have read access to the file, or if the access mode is "rw" and the application doesn't have both read and write access to the file.

close

RandomAccessFile

public void close() throws IOException

This method closes the random access file stream, releasing any resources associated with it.

IOException if an I/O error occurs.

getFD

RandomAccessFile

public final FileDescriptor getFD() throws IOException

This method determines the file descriptor associated with the random access file stream.

the file descriptor associated with the stream.

IOException if an I/O error occurs.

getFilePointer

RandomAccessFile

public long getFilePointer() throws IOException

This method determines the current read/write position in bytes of the random access file stream, which is the offset of the read/write position from the beginning of the stream.

the current read/write position of the stream.

IOException if an I/O error occurs.

length

RandomAccessFile

public long length() throws IOException

This method determines the length in bytes of the underlying file.

the length of the underlying file.

IOException if an I/O error occurs.

read

RandomAccessFile

public int read() throws IOException

This method reads a byte value from the random access file 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

RandomAccessFile

public int read(byte b[]) throws IOException

This method reads up to b.length bytes from the random access file stream into the byte array b, blocking until at least one byte is available.

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

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

IOException if an I/O error occurs.

read

RandomAccessFile

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

This method reads up to len bytes from the random access file stream into the byte array b beginning off bytes into the array, blocking until at least one byte is available.

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 total number of bytes read, or -1 if the end of the stream is reached.

IOException if an I/O error occurs.

readBoolean

RandomAccessFile

public final boolean readBoolean() throws IOException

This method reads a Boolean value (byte) from the random access file stream. A value of 0 is interpreted as false; 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

RandomAccessFile

public final byte readByte() throws IOException

This method reads a signed byte (8-bit) value from the random access file 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

RandomAccessFile

public final char readChar() throws IOException

This method reads a character (16-bit) value from the random access file 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

RandomAccessFile

public final double readDouble() throws IOException

This method reads a double (64-bit) value from the random access file 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

RandomAccessFile

public final float readFloat() throws IOException

This method reads a float (32-bit) value from the random access file 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

RandomAccessFile

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

This method reads up to b.length bytes from the random access file 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 value.

IOException if an I/O error occurs.

readFully

RandomAccessFile

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

This method reads up to len bytes from the random access file 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 value.

IOException if an I/O error occurs.

readInt

RandomAccessFile

public final int readInt() throws IOException

This method reads an integer (32-bit) value from the random access file 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

RandomAccessFile

public final String readLine() throws IOException

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

a string containing the line of text read.

IOException if an I/O error occurs.

readLong

RandomAccessFile

public final long readLong() throws IOException

This method reads a long (64-bit) value from the random access file stream, blocking until all eight bytes are read.

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

RandomAccessFile

public final short readShort() throws IOException

This method reads a short (16-bit) value from the random access file stream, blocking until both bytes are read.

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

RandomAccessFile

public final int readUnsignedByte() throws IOException

This method reads an unsigned byte (8-bit) value from the random access file stream, blocking until the byte is read.

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

RandomAccessFile

public final int readUnsignedShort() throws IOException

This method reads an unsigned short (16-bit) value from the random access file stream, blocking until both bytes are read.

the unsigned short value read.

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

IOException if an I/O error occurs.

readUTF

RandomAccessFile

public final String readUTF() throws IOException

This method reads a string that has been encoded using a modified UTF-8 format from the random access file stream, blocking until all bytes are read.

the string read.

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

UTFDataFormatException if the bytes read don't represent a valid UTF-8 encoding of a string.

IOException if an I/O error occurs.

seek

RandomAccessFile

public void seek(long pos) throws IOException

This method sets the current stream position to the specified absolute position; the position is absolute because it's always determined in relation to the beginning of the stream.

pos is the absolute position to seek to.

IOException if an I/O error occurs.

skipBytes

RandomAccessFile

public int skipBytes(int n) throws IOException

This method skips n bytes of data in the random access file 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.

write

RandomAccessFile

public void write(byte b[]) throws IOException

This method writes b.length bytes to the random access file stream from the byte array b.

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

IOException if an I/O error occurs.

write

RandomAccessFile

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

This method writes len bytes to the random access file 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

RandomAccessFile

public void write(int b) throws IOException

This method writes a byte value to the random access file stream.

b is the byte value to be written.

IOException if an I/O error occurs.

writeBoolean

RandomAccessFile

public final void writeBoolean(boolean v) throws IOException

This method writes a Boolean value to the random access file 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

RandomAccessFile

public final void writeByte(int v) throws IOException

This method writes a byte (8-bit) value to the random access file stream.

v is the byte value to be written.

IOException if an I/O error occurs.

writeBytes

RandomAccessFile

public final void writeBytes(String s) throws IOException

This method writes a string to the random access file stream as a sequence of bytes.

s is the string to be written as bytes.

IOException if an I/O error occurs.

writeChar

RandomAccessFile

public final void writeChar(int v) throws IOException

This method writes a character (16-bit) value to the random access file stream.

v is the character value to be written.

IOException if an I/O error occurs.

writeChars

RandomAccessFile

public final void writeChars(String s) throws IOException

This method writes a string to the random access file stream as a sequence of characters.

s is the string to be written as characters.

IOException if an I/O error occurs.

writeDouble

RandomAccessFile

public final void writeDouble(double v) throws IOException

This method writes a double (64-bit) value to the random access file stream.

v is the double value to be written.

IOException if an I/O error occurs.

writeFloat

RandomAccessFile

public final void writeFloat(float v) throws IOException

This method writes a float (32-bit) value to the random access file stream.

v is the float value to be written.

IOException if an I/O error occurs.

writeInt

RandomAccessFile

public final void writeInt(int v) throws IOException

This method writes an integer (32-bit) value to the random access file stream.

v is the integer value to be written.

IOException if an I/O error occurs.

writeLong

RandomAccessFile

public final void writeLong(long v) throws IOException

This method writes a long (64-bit) value to the random access file stream.

v is the long value to be written.

IOException if an I/O error occurs.

writeShort

RandomAccessFile

public final void writeShort(int v) throws IOException

This method writes a short (16-bit) value to the random access file stream.

v is the short value to be written.

IOException if an I/O error occurs.

writeUTF

RandomAccessFile

public final void writeUTF(String str) throws IOException

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

str is the string to be written.

IOException if an I/O error occurs.

SequenceInputStream

InputStream

The SequenceInputStream class implements an input stream that can combine several input streams serially so that they function together as a single input stream. Each input stream forming the sequence is read from in turn; the sequence input stream handles closing streams as they finish and switching to the next one. This is the class definition:

public class java.io.SequenceInputStream extends java.io.InputStream {
  // Constructors
  public SequenceInputStream(Enumeration e);
  public SequenceInputStream(InputStream s1, InputStream s2);

  // Methods
  public void close();
  public int read();
  public int read(byte buf[], int pos, int len);
}

SequenceInputStream

SequenceInputStream

public SequenceInputStream(Enumeration e)

This constructor creates a sequence input stream containing the specified enumerated list of input streams.

e is the list of input streams for the sequence.

SequenceInputStream

SequenceInputStream

public SequenceInputStream(InputStream s1, InputStream s2)

This constructor creates a sequence input stream containing the two specified input streams.

s1 is the first input stream in the sequence.

s2 is the second input stream in the sequence.

close

SequenceInputStream

public void close() throws IOException

This method closes the sequence input stream, releasing any resources associated with it. Additionally, this close method calls the close method for the substream currently being read from as well as the substreams that have yet to be read from.

IOException if an I/O error occurs.

close in class InputStream.

read

SequenceInputStream

public int read() throws IOException

This method reads a byte value from the currently active substream in the sequence input stream, blocking until the byte is read. If the end of the substream is reached, the close method is called on the substream and read begins reading from the next substream.

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

read in class InputStream.

read

SequenceInputStream

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

This method reads up to len bytes from the currently active substream in the sequence input stream into the byte array b beginning off bytes into the array, blocking until all bytes are read. If the end of the substream is reached, the close method is called on the substream and read begins reading from the next substream.

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 InputStream.

StreamTokenizer

Object

The StreamTokenizer class implements a string tokenizer stream, which parses an input stream into a stream of tokens. The StreamTokenizer class gives you different methods for establishing how the tokens are parsed. Each character read from the stream is evaluated as having zero or more of the following attributes: whitespace, alphabetic, numeric, string quote, or comment. Here is the definition for the class:

public class java.io.StreamTokenizer extends java.lang.Object {
  // Member Variables
  public double nval;
  public String sval;
  public int ttype;

  // possible values for the ttype member variable
  public final static int TT_EOF;
  public final static int TT_EOL;
  public final static int TT_NUMBER;
  public final static int TT_WORD;

  // Constructors
  public StreamTokenizer(InputStream I);

  // Methods
  public void commentChar(int ch);
  public void eolIsSignificant(boolean flag);
  public int lineno();
  public void lowerCaseMode(boolean fl);
  public int nextToken();
  public void ordinaryChar(int ch);
  public void ordinaryChars(int low, int hi);
  public void parseNumbers();
  public void pushBack();
  public void quoteChar(int ch);
  public void resetSyntax();
  public void whitespaceChars(int low, int hi);
  public void slashStarComments(boolean flag);
  public String toString();
  public void whitespaceChars(int low, int hi);
  public void wordChars(int low, int hi);
}

Member Variables

public double nval

This member variable holds a numeric token value whenever the ttype member variable is set to TT_NUMBER.

public String sval

This member variable holds a string representation of a word token whenever the ttype member variable is set to TT_WORD, or it holds the body of a quoted string token when ttype is set to a quote character.

public int ttype

This is the type of the current token, which can be one of the following:

public final static int TT_EOF

This is a constant token type representing the end-of-file token.

public final static int TT_EOL

This is a constant token type representing the end-of-line token.

public final static int TT_NUMBER

This is a constant token type identifying a numeric token; the actual numeric value is stored in nval.

public final static int TT_WORD

This is a constant token type identifying a word token; the actual word value is stored in sval.

StreamTokenizer

StreamTokenizer

public StreamTokenizer(InputStream I)

This constructor creates a string tokenizer stream that parses the specified input stream. By default, the string tokenizer stream recognizes numbers, strings quoted with single and double quotes, all alphabetic characters, and comments preceded by a / character.

I is the input stream to be parsed.

commentChar

StreamTokenizer

public void commentChar(int ch)

This method specifies what character starts single-line comments.

ch is the new single-line comment character.

eolIsSignificant

StreamTokenizer

public void eolIsSignificant(boolean flag)

This method establishes whether end-of-line characters are recognized as tokens.

flag is a Boolean value specifying whether end-of-line characters are treated as tokens; a value of true means end-of-line characters are treated as tokens, but a value of false means they are treated as whitespace.

lineno

StreamTokenizer

public int lineno()

This method determines the current line number of the string tokenizer stream.

the current line number of the stream.


lowerCaseMode

StreamTokenizer

public void lowerCaseMode(boolean flag)

This method establishes whether word tokens (TT_WORD) are forced to lowercase letters when they are parsed.

flag is a Boolean value specifying whether word tokens are forced to lowercase letters; a value of true means they are, but a value of false means they are left unmodified.

nextToken

StreamTokenizer

public int nextToken() throws IOException

This method parses the next token from the underlying input stream. After the token is parsed, the ttype member variable is set to the type of the token, but the value of some tokens is contained in either the nval or sval member variables, depending on the token type.

the type of the token.

IOException if an I/O error occurs.

ordinaryChar

StreamTokenizer

public void ordinaryChar(int ch)

This method establishes that the specified character is handled as an ordinary character by the tokenizer, meaning that the character is not interpreted as a comment character, word component, string delimiter, whitespace, or numeric character. Ordinary characters are parsed as single-character tokens.

ch is the character to be set as ordinary.

ordinaryChars

StreamTokenizer

public void ordinaryChars(int low, int hi)

This method establishes that the characters in the specified range are handled as ordinary characters by the tokenizer, meaning that the characters are not interpreted as comment characters, word components, string delimiters, whitespace, or numeric characters. Ordinary characters are parsed as single-character tokens.

low is the low end of the ordinary character range.

hi is the high end of the ordinary character range.

parseNumbers

StreamTokenizer

public void parseNumbers()

This method establishes that numbers should be parsed. When a number is parsed, the ttype member variable is set to TT_NUMBER, with the corresponding numeric value stored in nval.

pushBack

StreamTokenizer

public void pushBack()

This method pushes the current token back into the string tokenizer stream, meaning that the next call to nextToken results in this token being handled.

quoteChar

StreamTokenizer

public void quoteChar(int ch)

This method establishes that matching pairs of the specified character are used to delimit string constants. When a string constant is parsed, the ttype member variable is set to the delimiting character, with the corresponding string body stored in sval.

ch is the new string delimiter character.

resetSyntax

StreamTokenizer

public void resetSyntax()

This method resets the syntax table so that all characters are considered ordinary. An ordinary character is a character that isn't interpreted as a comment character, word component, string delimiter, whitespace, or numeric character. Ordinary characters are parsed as single-character tokens.

slashSlashComments

StreamTokenizer

public void slashSlashComments(boolean flag)

This method establishes whether C++ style comments (//) are recognized by the parser. A C++ style comment is defined by two consecutive forward slash characters, which start a comment that extends to the end of the line.

flag is a Boolean value specifying whether C++ style comments are recognized; a value of true means C++ style comments are recognized, but a value of false means they aren't treated specially.

slashStarComments

StreamTokenizer

public void slashStarComments(boolean flag)

This method establishes whether C style comments (/*...*/) are recognized by the parser. A C style comment is defined by a forward slash character followed by an asterisk to start a comment. The comment continues until a corresponding asterisk followed by a forward slash character is reached.

flag is a Boolean value specifying whether C style comments are recognized; a value of true means C style comments are recognized, but a value of false means they aren't treated specially.

toString

StreamTokenizer

public String toString()

This method determines the string representation of the current token in the string tokenizer stream.

the string representation of the current token.

toString in class Object.

whitespaceChars

StreamTokenizer

public void whitespaceChars(int low, int hi)

This method establishes that the characters in the specified range are handled as whitespace by the tokenizer, meaning that the characters serve only to separate tokens.

low is the low end of the whitespace character range.

hi is the high end of the whitespace character range.

wordChars

StreamTokenizer

public void wordChars(int low, int hi)

This method establishes that the characters in the specified range are handled as words by the tokenizer.

low is the low end of the word character range.

hi is the high end of the word character range.

StringBufferInputStream

InputStream

This class implements an input stream whose data is fed by a string. Note that only the lower 8 bits of each character in the string are used by this class. This is the definition for the StringBufferInputStream class:

public class java.io.StringBufferInputStream extends java.io.InputStream {
  // Member Variables
  protected String buffer;
  protected int count;
  protected int pos;

  // Constructors
  public StringBufferInputStream(String s);

  // 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

protected String buffer

This is the string buffer from which the data is read.

protected int count

This is the number of characters currently in the buffer.

protected int pos

This is the current read position in the buffer.

StringBufferInputStream

StringBufferInputStream

public StringBufferInputStream(String s)

This constructor creates a string buffer input stream based on the specified string. Note that the string buffer is not copied to create the input stream.

s is the input string buffer.

available

StringBufferInputStream

public int available()

This method determines the number of bytes that can be read from the string buffer input stream without blocking.

the number of available bytes.

available in class InputStream.

read

StringBufferInputStream

public int read()

This method reads a byte value from the string buffer input stream, which is the lower 8 bits of the next character in the underlying string buffer.

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

read in class InputStream.

read

StringBufferInputStream

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

This method reads up to len bytes from the string buffer input stream into the byte array b beginning off bytes into the array. Note that each byte is actually the lower 8 bits of the corresponding character in the underlying string buffer.

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

StringBufferInputStream

public void reset()

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

reset in class InputStream.

skip

StringBufferInputStream

public long skip(long n)

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

n is the number of bytes to skip.

the actual number of bytes skipped.

skip in class InputStream.

EOFException

IOException

This exception class signals that an end-of-file (EOF) has been reached unexpectedly during an input operation. This exception is primarily used by data input streams, which typically expect a binary file in a specific format, in which case an end-of-file is an unusual condition. Here is the definition for the EOFException class:

public class java.io.EOFException extends java.io.IOException {
  // Constructors
  public EOFException();
  public EOFException(String s);
}

EOFException

EOFException

public EOFException()

This constructor creates a default EOF exception with no detail message.

EOFException

EOFException

public EOFException(String s)

This constructor creates an EOF exception with the specified detail message containing information specific to this particular exception.

s is the detail message.

FileNotFoundException

IOException

This exception class signals that a file could not be found; here is the definition for the FileNotFoundException class:

public class java.io.FileNotFoundException extends java.io.IOException {
  // Constructors
  public FileNotFoundException();
  public FileNotFoundException(String s);
}

FileNotFoundException

FileNotFoundException

public FileNotFoundException()

This constructor creates a default file-not-found exception with no detail message.

FileNotFoundException

FileNotFoundException

public FileNotFoundException(String s)

This constructor creates a file-not-found exception with the specified detail message containing information specific to this particular exception.

s is the detail message.

IOException

Exception

This exception class signals that some kind of input/output (I/O) exception has occurred; this is the definition for the IOException class:

public class java.io.IOException extends java.lang.Exception {
// Constructors
public IOException();
public IOException(String s);
}

IOException

IOException

public IOException()

This constructor creates a default I/O exception with no detail message.

IOException

IOException

public IOException(String s)

This constructor creates an I/O exception with the specified detail message containing information specific to this particular exception.

s is the detail message.

InterruptedIOException

IOException

See also: InputStream, OutputStream, Thread.

This exception class signals that an input/output (I/O) operation has been interrupted; this is the definition for the InterruptedIOException class:

public class java.io.InterruptedIOException extends java.io.IOException {
  // Member Variables
  public int bytesTransferred;

  // Constructors
  public InterruptedIOException();
  public InterruptedIOException(String s);
}

Member Variables

public int bytesTransferred

This is the number of bytes that had been transferred during the I/O operation before it was interrupted.

InterruptedIOException

InterruptedIOException

public InterruptedIOException()

This constructor creates a default interrupted I/O exception with no detail message.

InterruptedIOException

InterruptedIOException

public InterruptedIOException(String s)

This constructor creates an interrupted I/O exception with the specified detail message containing information specific to this particular exception.

s is the detail message.

UTFDataFormatException

1-4-8 IOException

This exception class signals that a malformed UTF-8 string has been read in a data input stream. This is the definition for the UTFDataFormatException class:

public class java.io.UTFDataFormatException extends java.io.IOException {
  // Constructors
  public UTFDataFormatException();
  public UTFDataFormatException(String s);
}

UTFDataFormatException

UTFDataFormatException

public UTFDataFormatException()

This constructor creates a default UTF data format exception with no detail message.

UTFDataFormatException

UTFDataFormatException

public UTFDataFormatException(String s)

This constructor creates a UTF data format exception with the specified detail message containing information specific to this particular exception.

s is the detail message.