Class java.io.FileInputStream
java.lang.Object
|
+----java.io.InputStream
|
+----java.io.FileInputStream
- public class FileInputStream
- extends InputStream
A file input stream is an input stream for reading data from a
File
or from a FileDescriptor
.
- Since:
- JDK1.0
- See Also:
- File, FileDescriptor, FileOutputStream
Method Summary
|
int
|
available()
Returns the number of bytes that can be read from this file input
stream without blocking.
|
void
|
close()
Closes this file input stream and releases any system resources
associated with the stream.
|
void
|
finalize()
Ensures that the close method of this file input stream is
called when there are no more references to it.
|
FileDescriptor
|
getFD()
Returns the opaque file descriptor object associated with this stream.
|
int
|
read()
Reads a byte of data from this input stream.
|
int
|
read(byte[] b)
Reads up to b.length bytes of data from this input
stream into an array of bytes.
|
int
|
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this input stream
into an array of bytes.
|
long
|
skip(long n)
Skips over and discards n bytes of data from the
input stream.
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FileInputStream
public FileInputStream(String name) throws FileNotFoundException
- Creates an input file stream to read from a file with the
specified name.
- Parameters:
name
- the system-dependent file name.
- Throws:
- FileNotFoundException - if the file is not found.
- SecurityException - if a security manager exists, its
checkRead
method is called with the name
argument to see if the application is allowed read access
to the file. - See Also:
- checkRead(java.lang.String)
FileInputStream
public FileInputStream(File file) throws FileNotFoundException
- Creates an input file stream to read from the specified
File
object.
- Parameters:
file
- the file to be opened for reading.
- Throws:
- FileNotFoundException - if the file is not found.
- SecurityException - if a security manager exists, its
checkRead
method is called with the pathname
of this File
argument to see if the
application is allowed read access to the file. - See Also:
- getPath(), checkRead(java.lang.String)
FileInputStream
public FileInputStream(FileDescriptor fdObj)
- Creates an input file stream to read from the specified file descriptor.
- Parameters:
fdObj
- the file descriptor to be opened for reading.
- Throws:
- 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. - See Also:
- checkRead(java.io.FileDescriptor)
read
public int read() throws IOException
- Reads a byte of data from this input stream. This method blocks
if no input is yet available.
- Returns:
- the next byte of data, or
-1
if the end of the
file is reached. - Throws:
- 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.
- Parameters:
b
- the buffer into which the data is read.
- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of
the file has been reached. - Throws:
- 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.
- Parameters:
b
- the buffer into which the data is read.
off
- the start offset of the data.
len
- the maximum number of bytes read.
- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of
the file has been reached. - Throws:
- 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 0
. The actual number of bytes skipped is returned.
- Parameters:
n
- the number of bytes to be skipped.
- Returns:
- the actual number of bytes skipped.
- Throws:
- IOException - if an I/O error occurs.
- Overrides:
- skip in class InputStream
available
public int available() throws IOException
- Returns the number of bytes that can be read from this file input
stream without blocking.
- Returns:
- the number of bytes that can be read from this file input
stream without blocking.
- Throws:
- 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.
- Throws:
- IOException - if an I/O error occurs.
- Overrides:
- close in class InputStream
getFD
public final FileDescriptor getFD() throws IOException
- Returns the opaque file descriptor object associated with this stream.
- Returns:
- the file descriptor object associated with this stream.
- Throws:
- IOException - if an I/O error occurs.
- See Also:
- FileDescriptor
finalize
protected void finalize() throws IOException
- Ensures that the
close
method of this file input stream is
called when there are no more references to it.
- Throws:
- IOException - if an I/O error occurs.
- Overrides:
- finalize in class Object
- See Also:
- close()
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.