java.io
Class FileInputStream
java.io.FileInputStream
- public class FileInputStream
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. |
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.
- 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.
- 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.
- Returns:
- the next byte of data, or -1 if the end of the file is reached.
- Throws:
- IOException - if an I/O error occurs.