java.io.FileInputStream
java.io.InputStream
None
None
JDK 1.0 or later
The FileInputStream class represents a byte stream that reads data from a file. The file can be specified using a FileDescriptor, a File object, or a String that represents a pathname. All of the constructors can throw a SecurityException if the application does not have permission to read from the specified file.
FileInputStream provides a low-level interface for reading data from a file. You should wrap a FileInputStream with a DataInputStream if you need a higher-level interface that can handle reading strings and binary data. You should also think about wrapping a FileInputStream with a BufferedInputStream to increase reading efficiency.
Data must be read sequentially from a FileInputStream; you can skip forward, but you cannot move back. If you need random access to file data, use the RandomAccessFile class instead.
public class java.io.FileInputStream extends java.io.InputStream { // Constructors public FileInputStream(String name); public FileInputStream(File file); public FileInputStream(FileDescriptor fdObj); // Public Instance Methods public native int available(); public native void close(); public final FileDescriptor getFD(); public native int read(); public int read(byte[] b); public int read(byte[] b, int off, int len); public native long skip(long n); // Protected Instance Methods protected void finalize(); }
A String that contains the pathname of the file to be accessed. The path must conform to the requirements of the native operating system.
If the named file cannot be found.
If the application does not have permission to read the named file.
This constructor creates a FileInputStream that gets its input from the file named by the specified String.
The File to use as input.
If the named file cannot be found.
If the application does not have permission to read the named file.
This constructor creates a FileInputStream that gets its input from the file represented by the specified File.
The FileDescriptor of the file to use as input.
If the application does not have permission to read the specified file.
If FileDescriptor is null.
This constructor creates a FileInputStream that gets its input from the file identified by the given FileDescriptor.
The number of bytes that can be read from the file without blocking.
If any kind of I/O error occurs.
InputStream.available()
This method returns the number of available bytes of data. Initially, this is the length of the file.
If any kind of I/O error occurs.
InputStream.close()
This method closes this file input stream and releases any resources used by it.
The file descriptor for the file that supplies data for this stream.
If there is no FileDescriptor associated with this object.
This method returns the file descriptor associated with the data source of this FileInputStream.
The next byte of data or -1 if the end of the stream is encountered.
If any kind of I/O error occurs.
InputStream.read()
This method reads the next byte of data from the file. The method blocks if no input is available.
An array of bytes to be filled from the stream.
The actual number of bytes read or -1 if the end of the stream is encountered immediately.
If any kind of I/O error occurs.
InputStream.read(byte[])
This method reads data into the given array. The method fills the array if enough bytes are available. The method blocks until some input is available.
An array of bytes to be filled from the stream.
An offset into the byte array.
The number of bytes to read.
The actual number of bytes read or -1 if the end of the stream is encountered immediately.
If any kind of I/O error occurs.
InputStream.read(byte[], int, int)
This method reads len bytes of data into the given array, starting at element off. The method blocks until some input is available.
The number of bytes to skip.
The actual number of bytes skipped.
If any kind of I/O error occurs.
FilterInputStream.skip()
This method skips n bytes of input in the stream.
If any kind of I/O error occurs.
Object.finalize()
This method is called when the FileInputStream is garbage collected to ensure that close() is called. If the stream has a valid file descriptor, the close() method is called to free the system resources used by this stream.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
getClass() |
Object |
hashCode() |
Object |
mark(int) |
InputStream |
markSupported() |
InputStream |
notify() |
Object |
notifyAll() |
Object |
reset() |
InputStream |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
BufferedInputStream, DataInputStream, File, FileDescriptor, FileNotFoundException, InputStream, IOException, NullPointerException, RandomAccessFile, SecurityException
This HTML Help has been published using the chm2web software. |