Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » io » [javadoc | source]
java.io
public class: FileInputStream [javadoc | source]
java.lang.Object
   java.io.InputStream
      java.io.FileInputStream

All Implemented Interfaces:
    Closeable

Direct Known Subclasses:
    SocketInputStream

A specialized InputStream that reads from a file in the file system. All read requests made by calling methods in this class are directly forwarded to the equivalent function of the underlying operating system. Since this may induce some performance penalty, in particular if many small read requests are made, a FileInputStream is often wrapped by a BufferedInputStream.
Field Summary
 FileDescriptor fd    The FileDescriptor representing this {@code FileInputStream}. 
 boolean innerFD     
Constructor:
 public FileInputStream(File file) throws FileNotFoundException 
    Constructs a new {@code FileInputStream} based on {@code file}.
    Parameters:
    file - the file from which this stream reads.
    Throws:
    FileNotFoundException - if {@code file} does not exist.
    SecurityException - if a {@code SecurityManager} is installed and it denies the read request.
 public FileInputStream(FileDescriptor fd) 
    Constructs a new {@code FileInputStream} on the FileDescriptor {@code fd}. The file must already be open, therefore no {@code FileNotFoundException} will be thrown.
    Parameters:
    fd - the FileDescriptor from which this stream reads.
    Throws:
    NullPointerException - if {@code fd} is {@code null}.
    SecurityException - if a {@code SecurityManager} is installed and it denies the read request.
 public FileInputStream(String fileName) throws FileNotFoundException 
    Constructs a new {@code FileInputStream} on the file named {@code fileName}. The path of {@code fileName} may be absolute or relative to the system property {@code "user.dir"}.
    Parameters:
    fileName - the path and name of the file from which this stream reads.
    Throws:
    FileNotFoundException - if there is no file named {@code fileName}.
    SecurityException - if a {@code SecurityManager} is installed and it denies the read request.
Method from java.io.FileInputStream Summary:
available,   close,   finalize,   getChannel,   getFD,   read,   read,   read,   skip
Methods from java.io.InputStream:
available,   close,   mark,   markSupported,   read,   read,   read,   reset,   skip
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.FileInputStream Detail:
 public int available() throws IOException 
    Returns the number of bytes that are available before this stream will block. This method always returns the size of the file minus the current position.
 public  void close() throws IOException 
    Closes this stream.
 protected  void finalize() throws IOException 
    Ensures that all resources for this stream are released when it is about to be garbage collected.
 public FileChannel getChannel() 
    Returns the FileChannel equivalent to this input stream.

    The file channel is read-only and has an initial position within the file that is the same as the current position of this stream within the file. All changes made to the underlying file descriptor state via the channel are visible by the input stream and vice versa.

 public final FileDescriptor getFD() throws IOException 
    Returns the FileDescriptor representing the operating system resource for this stream.
 public int read() throws IOException 
    Reads a single byte from this stream and returns it as an integer in the range from 0 to 255. Returns -1 if the end of this stream has been reached.
 public int read(byte[] buffer) throws IOException 
    Reads bytes from this stream and stores them in the byte array {@code buffer}.
 public int read(byte[] buffer,
    int offset,
    int count) throws IOException 
    Reads at most {@code count} bytes from this stream and stores them in the byte array {@code buffer} starting at {@code offset}.
 public long skip(long count) throws IOException 
    Skips {@code count} number of bytes in this stream. Subsequent {@code read()}'s will not return these bytes unless {@code reset()} is used. This method may perform multiple reads to read {@code count} bytes.