Package java.io Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class FileInputStream

Constructors , Methods

public  class  java.io.FileInputStream
    extends  java.io.InputStream  
{
        // Constructors
    public FileInputStream(File  file);	
    public FileInputStream(FileDescriptor  fdObj);	
    public FileInputStream(String  name);	

        // Methods
    public int available();	
    public void close();	
    protected void finalize();	
    public final FileDescriptor getFD();	
    public int read();	
    public int read(byte  b[]);	
    public int read(byte  b[], int  off, int  len);	
    public long skip(long  n);	
}

A file input stream is an input stream for reading data from a File or from a FileDescriptor .


Constructors


FileInputStream

public FileInputStream(File  file) 
throws FileNotFoundException 

Creates an input file stream to read from the specified File object

ParameterDescription
file the file to be opened for reading

Throw:

FileNotFoundException

If the file is not found.

Throw:

SecurityException

If a security manager exists, its checkRead method is called with the path name of this File argument to see if the application is allowed read access to the file. This may result in a security exception .


FileInputStream

public FileInputStream(FileDescriptor  fdObj) 

Creates an input file stream to read from the specified file descriptor

ParameterDescription
fdObj the file descriptor to be opened for reading

Throw:

SecurityException

If a security manager exists, its checkRead method is called with the file descriptor to see if the application is allowed to read from the specified file descriptor. This may result in a security exception .


FileInputStream

public FileInputStream(String  name) 
throws FileNotFoundException 

Creates an input file stream to read from a file with the specified name.

If a security manager exists, its checkRead method is called with the name argument t to see if the application is allowed read access to the file. This may result in a security exception .

ParameterDescription
name the system dependent file name

Throw:

FileNotFoundException

If the file is not found.

Throw:

SecurityException

If a security manager exists, its checkRead method is called with the name argument t to see if the application is allowed read access to the file. This may result in a security exception .


Methods


available

public int available() 
throws IOException 

Return Value:

Returns the number of bytes that can be read from this file input stream without blocking.

Throw:

IOException

If an I/O error occurs.

Overrides:

available in class InputStream .


close

public void close() 
throws IOException 

Closes this file input stream and releases any system resources associated with the stream.

Throw:

IOException

If an I/O error occurs.

Overrides:

close in class InputStream .


finalize

protected void finalize() 
throws IOException 

This finalize method ensures that the close method of this file input stream is called when there are no more references to it.

Throw:

IOException

If an I/O error occurs.

Overrides:

finalize in class Object .


getFD

public final FileDescriptor getFD() 
throws IOException 

Return Value:

Returns the file descriptor object associated with this stream.

Throw:

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.

Return Value:

Returns the next byte of data, or -1 if the end of the file is reached.

Throw:

IOException

If an I/O error occurs.

Overrides:

read in class InputStream .


read

public int read(byte  b[]) 
throws IOException 

Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Return Value:

Returns the total number of bytes read into the buffer, or -1 is there is no more data because the end of the file has been reached.

ParameterDescription
b the buffer into which the data is read

Throw:

IOException

If an I/O error occurs.

Overrides:

read in class InputStream .


read

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

Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Return Value:

Returns the total number of bytes read into the buffer, or -1 is there is no more data because the end of the file has been reached.

ParameterDescription
b the buffer into which the data is read
off the start offset of the data
len the maximum number of bytes read

Throw:

IOException

If an I/O error occurs.

Overrides:

read in class InputStream .


skip

public long skip(long  n) 
throws IOException 

Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly zero. The actual number of bytes skipped is returned.

Return Value:

Returns the actual number of bytes skipped.

ParameterDescription
n the number of bytes to be skipped

Throw:

IOException

If an I/O error occurs.

Overrides:

skip in class InputStream .



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