Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.io.InputStream
java.io.FileInputStream
public class FileInputStream
extends InputStream
Constructor Summary | |
| |
| |
|
Method Summary | |
int |
|
void |
|
protected void |
|
FileChannel |
|
FileDescriptor |
|
int |
|
int |
|
int |
|
long |
|
Methods inherited from class java.io.InputStream | |
available , close , mark , markSupported , read , read , read , reset , skip |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public FileInputStream(File file) throws FileNotFoundException
This method initializes aFileInputStream
to read from the specifiedFile
object. A security check is first made to determine whether or not access to this file is allowed. This is done by calling thecheckRead()
method of theSecurityManager
(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.
- Parameters:
file
- TheFile
object this stream should read from
- Throws:
SecurityException
- If read access to the file is not allowedFileNotFoundException
- If the file does not exist or if it is a directory.
public FileInputStream(FileDescriptor fdObj)
This method initializes aFileInputStream
to read from the specifiedFileDescriptor
object. A security check is first made to determine whether or not access to this file is allowed. This is done by calling thecheckRead()
method of theSecurityManager
(if one exists) with the specifiedFileDescriptor
An exception is thrown if reading is not allowed.
- Parameters:
fdObj
- TheFileDescriptor
object this stream should read from
- Throws:
SecurityException
- If read access to the file is not allowed
public FileInputStream(String name) throws FileNotFoundException
This method initializes aFileInputStream
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 thecheckRead()
method of theSecurityManager
(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.
- Parameters:
name
- The name of the file this stream should read from
- Throws:
SecurityException
- If read access to the file is not allowedFileNotFoundException
- If the file does not exist or if it is a directory
public int available() throws IOException
This method returns the number of bytes that can be read from this stream before a read can block. A return of 0 indicates that blocking might (or might not) occur on the very next read attempt.This method returns the number of unread bytes remaining in the file if the descriptor being read from is an actual file. If this method is reading from a ''special'' file such a the standard input, this method will return the appropriate value for the stream being read.
Be aware that reads on plain files that do not reside locally might possibly block even if this method says they should not. For example, a remote server might crash, preventing an NFS mounted file from being read.
- Overrides:
- available in interface InputStream
- Returns:
- The number of bytes that can be read before blocking could occur
- Throws:
IOException
- If an error occurs
public void close() throws IOException
This method closes the stream. Any futher attempts to read from the stream will likely generate an IOException since the underlying file will be closed.
- Specified by:
- close in interface Closeable
- close in interface AutoCloseable
- Overrides:
- close in interface InputStream
- Throws:
IOException
- If an error occurs.
public FileChannel getChannel()
This method creates a java.nio.channels.FileChannel. Nio does not allow one to create a file channel directly. A file channel must be created by first creating an instance of Input/Output/RandomAccessFile and invoking the getChannel() method on it.
public final FileDescriptor getFD() throws IOException
This method returns aFileDescriptor
object representing the underlying native file handle of the file this stream is reading from
- Returns:
- A
FileDescriptor
for this stream
- Throws:
IOException
- If an error occurs
public int read() throws IOException
This method reads an unsigned byte from the input stream and returns it as an int in the range of 0-255. This method also will return -1 if the end of the stream has been reached.This method will block until the byte can be read.
- Overrides:
- read in interface InputStream
- Returns:
- The byte read or -1 if end of stream
- Throws:
IOException
- If an error occurs
public int read(byte[] buf) throws IOException
This method reads bytes from a stream and stores them into a caller supplied buffer. This method attempts to completely fill the buffer, but can return before doing so. 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 an overloaded read method like so:
read(buf, 0, buf.length)
- Overrides:
- read in interface InputStream
- Parameters:
buf
- The buffer into which the bytes read will be stored.
- Returns:
- The number of bytes read or -1 if end of stream.
- Throws:
IOException
- If an error occurs.
public int read(byte[] buf, int offset, int len) throws IOException
This method read bytes from a stream and stores them into a caller supplied buffer. It starts storing the data at indexoffset
into the buffer and attempts to readlen
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.
- Overrides:
- read in interface InputStream
- Parameters:
buf
- The array into which the bytes read should be storedoffset
- The offset into the array to start storing byteslen
- The requested number of bytes to read
- Returns:
- The actual number of bytes read, or -1 if end of stream.
- Throws:
IOException
- If an error occurs.
public long skip(long numBytes) throws IOException
This method skips the specified number of bytes in the stream. It returns the actual number of bytes skipped, which may be less than the requested amount.
- Overrides:
- skip in interface InputStream
- Parameters:
numBytes
- The requested number of bytes to skip
- Returns:
- The actual number of bytes skipped.
- Throws:
IOException
- If an error occurs