CHAPTER 22: The Package java.io Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

22.4 The Class java.io.FileInputStream

22.4.1 FileInputStream , 22.4.2 FileInputStream , 22.4.3 FileInputStream , 22.4.4 getFD , 22.4.5 read , 22.4.6 read , 22.4.7 read , 22.4.8 skip , 22.4.9 available , 22.4.10 close , 22.4.11 finalize

A file input stream obtains input bytes from a file in a file system. What files are available depends on the host environment.

public class FileInputStream extends InputStream  {
	public FileInputStream(String path)
		throws SecurityException, FileNotFoundException;
	public FileInputStream(File file)
		throws SecurityException, FileNotFoundException;
	public FileInputStream(FileDescriptor fdObj)
		throws SecurityException;
	public native int read() throws IOException;
	public int read(byte[] b)
		throws IOException, NullPointerException;
	public int read(byte[] b, int off, int len)
		throws IOException, NullPointerException,
			IndexOutOfBoundsException;
	public native long skip(long n) throws IOException;
	public native int available() throws IOException;
	public native void close() throws IOException;
	public final FileDescriptor getFD() throws IOException;
	protected void finalize() throws IOException;
}


22.4.1 FileInputStream

public FileInputStream(String path)
	throws SecurityException, FileNotFoundException

This constructor initializes a newly created FileInputStream by opening a connection to an actual file, the file named by the path name path in the file system. A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkRead method (S20.17.19) is called with the path argument as its argument.

If the actual file cannot be opened, a FileNotFoundException is thrown.


22.4.2 FileInputStream

public FileInputStream(File file)
	throws SecurityException, FileNotFoundException

This constructor initializes a newly created FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system. A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkRead method (S20.17.19) is called with the path represented by the file argument as its argument.

If the actual file cannot be opened, a FileNotFoundException is thrown.


22.4.3 FileInputStream

public FileInputStream(FileDescriptor fdObj)
	throws SecurityException

This constructor initializes a newly created FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

First, if there is a security manager, its checkRead method (S20.17.18) is called with the file descriptor fdObj as its argument.


22.4.4 getFD

public final FileDescriptor getFD() throws IOException

This method returns the FileDescriptor object (S22.26) that represents the connection to the actual file in the file system being used by this FileInputStream.


22.4.5 read

public int read() throws IOException;

The byte for this operation is read from the actual file with which this file input stream is connected.

Implements the read method of InputStream (S22.3.1).


22.4.6 read

public int read(byte[] b)
	throws IOException, NullPointerException

Bytes for this operation are read from the actual file with which this file input stream is connected.

Overrides the read method of InputStream (S22.3.2).


22.4.7 read

public int read(byte[] b, int off, int len)
	throws IOException, NullPointerException,       IndexOutOfBoundsException

Bytes for this operation are read from the actual file with which this file input stream is connected.

Overrides the read method of InputStream (S22.3.3).


22.4.8 skip

public long skip(long n) throws IOException

Bytes for this operation are read from the actual file with which this file input stream is connected.

Overrides the skip method of InputStream (S22.3.4).


22.4.9 available

public int available() throws IOException

Overrides the available method of InputStream (S22.3.5).


22.4.10 close

public void close() throws IOException

This file input stream is closed and may no longer be used for reading bytes.

Overrides the close method of InputStream (S22.3.6).


22.4.11 finalize

protected void finalize() throws IOException

A FileInputStream uses finalization to clean up the connection to the actual file.

Top© 1996 Sun Microsystems, Inc. All rights reserved.