| |
|
| java.lang.Object java.io.InputStream java.io.FileInputStream
FileInputStream | public class FileInputStream extends InputStream implements Closeable(Code) | | FileInputStream is a class for reading bytes from a file. This class may also
be used with other InputStreams, ie: BufferedInputStream, to read data from a
file with buffering.
See Also: FileOutputStream |
Constructor Summary | |
public | FileInputStream(File file) Constructs a new FileInputStream on the File file . | public | FileInputStream(FileDescriptor fd) Constructs a new FileInputStream on the FileDescriptor fd . | public | FileInputStream(String fileName) Constructs a new FileInputStream on the file named fileName .
If the file does not exist, the FileNotFoundException is
thrown. |
Method Summary | |
public int | available() Answers a int representing then number of bytes that are available before
this InputStream will block. | public void | close() Close the FileInputStream. | protected void | finalize() This method ensures that all resources for this file are released when it
is about to be garbage collected. | public FileChannel | getChannel() Answers 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 the FileInputStream within
the file. | final public FileDescriptor | getFD() Answers the FileDescriptor representing the operating system resource for
this FileInputStream. | public int | read() Reads a single byte from this FileInputStream and returns the result as
an int. | public int | read(byte[] buffer) Reads bytes from the FileInputStream and stores them in byte array
buffer . | public int | read(byte[] buffer, int offset, int count) Reads at most count bytes from the FileInputStream and
stores them in byte array buffer starting at
offset . | public long | skip(long count) Skips count number of bytes in this FileInputStream.
Subsequent read() 's will not return these bytes unless
reset() is used. |
FileInputStream | public FileInputStream(String fileName) throws FileNotFoundException(Code) | | Constructs a new FileInputStream on the file named fileName .
If the file does not exist, the FileNotFoundException is
thrown. The fileName may be absolute or relative to the
System property "user.dir" .
Parameters: fileName - the file on which to stream reads. throws: FileNotFoundException - If the fileName is not found. |
available | public int available() throws IOException(Code) | | Answers a int representing then number of bytes that are available before
this InputStream will block. This method always returns the size of the
file minus the current position.
the number of bytes available before blocking. throws: IOException - If an error occurs in this stream. |
close | public void close() throws IOException(Code) | | Close the FileInputStream.
throws: IOException - If an error occurs attempting to close this FileInputStream. |
finalize | protected void finalize() throws IOException(Code) | | This method ensures that all resources for this file are released when it
is about to be garbage collected.
throws: IOException - If an error occurs attempting to finalize thisFileInputStream. |
getChannel | public FileChannel getChannel()(Code) | | Answers 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 the FileInputStream within
the file. All changes made to the underlying file descriptor state via
the channel are visible by the input stream and vice versa.
the file channel representation for this FileInputStream. |
getFD | final public FileDescriptor getFD() throws IOException(Code) | | Answers the FileDescriptor representing the operating system resource for
this FileInputStream.
the FileDescriptor for this FileInputStream. throws: IOException - If an error occurs attempting to get the FileDescriptor ofthis FileInputStream. |
read | public int read() throws IOException(Code) | | Reads a single byte from this FileInputStream and returns the result as
an int. The low-order byte is returned or -1 of the end of stream was
encountered.
the byte read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
read | public int read(byte[] buffer) throws IOException(Code) | | Reads bytes from the FileInputStream and stores them in byte array
buffer . Answer the number of bytes actually read or -1 if
no bytes were read and end of stream was encountered.
Parameters: buffer - the byte array in which to store the read bytes. the number of bytes actually read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
read | public int read(byte[] buffer, int offset, int count) throws IOException(Code) | | Reads at most count bytes from the FileInputStream and
stores them in byte array buffer starting at
offset . Answer the number of bytes actually read or -1 if
no bytes were read and end of stream was encountered.
Parameters: buffer - the byte array in which to store the read bytes. Parameters: offset - the offset in buffer to store the read bytes. Parameters: count - the maximum number of bytes to store in buffer . the number of bytes actually read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
skip | public long skip(long count) throws IOException(Code) | | Skips count number of bytes in this FileInputStream.
Subsequent read() 's will not return these bytes unless
reset() is used. This method may perform multiple reads to
read count bytes.
Parameters: count - the number of bytes to skip. the number of bytes actually skipped. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
|
|
|