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; ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.