public class FileInputStream extends InputStream
| Constructor and Description |
|---|
FileInputStream(File f) |
FileInputStream(String name)
This method initializes a
FileInputStream to read from the
specified named file. |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
This method returns the number of bytes that can be read from this
stream before a read can block.
|
int |
read()
This method reads an unsigned byte from the input stream and returns it
as an int in the range of 0-255.
|
int |
read(byte[] b,
int off,
int len)
This method read bytes from a stream and stores them into a
caller supplied buffer.
|
long |
skip(long n)
This method skips the specified number of bytes in the stream.
|
close, mark, markSupported, read, resetpublic FileInputStream(File f) throws FileNotFoundException
FileNotFoundExceptionpublic FileInputStream(String name) throws IOException
FileInputStream to read from the
specified named file. A security check is first made to determine
whether or not access to this file is allowed. This is done by
calling the checkRead() method of the
SecurityManager
(if one exists) with the name of this file. An exception is thrown
if reading is not allowed. If the file does not exist, an exception
is also thrown.name - The name of the file this stream should read fromIOExceptionpublic int available()
throws IOException
InputStreamThis method always returns 0 in this class
available in class InputStreamIOException - If an error occurspublic int read()
throws IOException
InputStreamThis method will block until the byte can be read.
read in class InputStreamIOException - If an error occurspublic int read(byte[] b,
int off,
int len)
throws IOException
InputStreamoff into the buffer and attempts to read
len bytes. This method can return before reading the
number of bytes requested. The actual number of bytes read is
returned as an int. A -1 is returned to indicate the end of the
stream.
This method will block until some data can be read.
This method operates by calling the single byte read() method
in a loop until the desired number of bytes are read. The read loop
stops short if the end of the stream is encountered or if an IOException
is encountered on any read operation except the first. If the first
attempt to read a bytes fails, the IOException is allowed to propagate
upward. And subsequent IOException is caught and treated identically
to an end of stream condition. Subclasses can (and should if possible)
override this method to provide a more efficient implementation.
read in class InputStreamb - The array into which the bytes read should be storedoff - The offset into the array to start storing byteslen - The requested number of bytes to readIOException - If an error occurs.public long skip(long n)
throws IOException
InputStreamThis method reads and discards bytes into a byte array until the specified number of bytes were skipped or until either the end of stream is reached or a read attempt returns a short count. Subclasses can override this metho to provide a more efficient implementation where one exists.
skip in class InputStreamn - The requested number of bytes to skipIOException - If an error occurs