Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 128
نمايش فراداده

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; public long

skip (long

n ) throws IOException; native // Protected Methods Overriding Object protected void

finalize ( ) throws IOException; }