java.io
Class FileInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FileInputStream

public class FileInputStream
extends InputStream

File input stream, can be constructed from a file descriptor or a file name.

See Also:
FileOutputStream, File

Constructor Summary
FileInputStream(File file)
          Creates an input file from the specified File object.
FileInputStream(FileDescriptor fdObj)
           
FileInputStream(String name)
          Creates an input file with the specified system dependent file name.
 
Method Summary
 int available()
          Returns the number of bytes that can be read without blocking.
 void close()
          Closes the input stream.
protected  void finalize()
          Closes the stream when garbage is collected.
 FileDescriptor getFD()
          Returns the opaque file descriptor object associated with this stream.
 int read()
          Reads a byte of data.
 int read(byte[] b)
          Reads data into an array of bytes.
 int read(byte[] b, int off, int len)
          Reads data into an array of bytes.
 long skip(long n)
          Skips n bytes of input.
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileInputStream

public FileInputStream(String name)
                throws FileNotFoundException
Creates an input file with the specified system dependent file name.

Parameters:
name - the system dependent file name
Throws:
IOException - If the file is not found.
FileNotFoundException

FileInputStream

public FileInputStream(File file)
                throws FileNotFoundException
Creates an input file from the specified File object.

Parameters:
file - the file to be opened for reading
Throws:
IOException - If the file is not found.
FileNotFoundException

FileInputStream

public FileInputStream(FileDescriptor fdObj)
Method Detail

read

public int read()
         throws IOException
Reads a byte of data. This method will block if no input is available.

Specified by:
read in class InputStream
Returns:
the byte read, or -1 if the end of the stream is reached.
Throws:
IOException - If an I/O error has occurred.

read

public int read(byte[] b)
         throws IOException
Reads data into an array of bytes. This method blocks until some input is available.

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read
Returns:
the actual number of bytes read. -1 is returned if the end of stream is reached.
Throws:
IOException - If an I/O error has occurred.

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads data into an array of bytes. This method blocks until some input is available.

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read. -1 is returned when the end of the stream is reached.
Throws:
IOException - If an I/O error has occurred.

skip

public long skip(long n)
          throws IOException
Skips n bytes of input.

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to be skipped
Returns:
the actual number of bytes skipped.
Throws:
IOException - If an I/O error has occurred.

available

public int available()
              throws IOException
Returns the number of bytes that can be read without blocking.

Overrides:
available in class InputStream
Returns:
the number of available bytes, which is initially equal to the file size.
IOException

close

public void close()
           throws IOException
Closes the input stream. This method must be called to release any resources associated with the stream.

Overrides:
close in class InputStream
Throws:
IOException - If an I/O error has occurred.

getFD

public final FileDescriptor getFD()
                           throws IOException
Returns the opaque file descriptor object associated with this stream.

Returns:
the file descriptor.
IOException

finalize

protected void finalize()
                 throws IOException
Closes the stream when garbage is collected.

Overrides:
finalize in class Object
IOException