Name
FileInputStream
Synopsis
This class is a subclass of
InputStream that reads bytes from a file specified
by name or by a File or
FileDescriptor object. read( )
reads a byte or array of bytes from the file. It returns -1 when the
end-of-file has been reached. To read binary data, you typically use
this class in conjunction with a
BufferedInputStream and
DataInputStream. To read
text, you typically use it
with an InputStreamReader and
BufferedReader. Call close(
)
to close the file when input is no longer needed.
In Java 1.4 and later, use getChannel(
)
to obtain a
FileChannel object for reading from the underlying
file using the New I/O API of java.nio and its
subpackages.
Figure 9-15. java.io.FileInputStream
public class FileInputStream extends InputStream { // Public Constructors public FileInputStream(String name) throws FileNotFoundException; public FileInputStream(File file) throws FileNotFoundException; public FileInputStream(FileDescriptor fdObj); // Public Instance Methods 1.4 public java.nio.channels.FileChannel getChannel( ); public final FileDescriptor getFD( ) throws IOException; // Public Methods Overriding InputStream public int available( ) throws IOException; native public void close( ) throws IOException; public int read( ) throws IOException; native public int read(byte[ ] b) throws IOException; public int read(byte[ ] b, int off, int len) throws IOException; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access