java.io
Class FileInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FileInputStream
- public class FileInputStream
- extends InputStream
A FileInputStream obtains input bytes from a file in a file system.
|
Constructor Summary |
FileInputStream(File file)
Creates a FileInputStream by opening a connection
to an actual file, the file named by the File object file in
the file system. |
|
Method Summary |
void |
close()
Closes this file input stream and releases any system resources associated with the stream. |
int |
read()
Reads a byte of data from this input stream. |
int |
read(byte[] buf,
int start,
int len)
Reads up to len bytes of data from this input stream into an array of bytes. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FileInputStream
public FileInputStream(File file)
throws FileNotFoundException
- Creates a
FileInputStream by opening a connection
to an actual file, the file named by the File object file in
the file system.
- Parameters:
File - file - the file to be opened for reading.- Throws:
FileNotFoundException - if the file does not exist, is
a directory rather than a regular file, or for some other
reason cannot be opened for reading.
close
public void close()
throws IOException
- Closes this file input stream and releases any system resources associated with the stream.
- Overrides:
close in class InputStream
- Throws:
IOException - if an I/O error occurs.
read
public int read(byte[] buf,
int start,
int len)
throws IOException
- Reads up to len bytes of data from this input stream into an array of bytes.
- Overrides:
read in class InputStream
- Parameters:
b - the buffer into which the data is read.off - the start offset of the data.len - the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or -1
if there is no more data because the end of the file has been
reached.
- Throws:
IOException - if an I/O error occurs.
read
public int read()
throws IOException
- Reads a byte of data from this input stream. This method blocks if no input is yet available.
- Overrides:
read in class InputStream
- Returns:
- the next byte of data, or -1 if the end of the file is reached.
- Throws:
IOException - if an I/O error occurs.