Packages This Package Prev Next Index
§2.9 Class FileInputStream
public class java.io.FileInputStream
extends java.io.InputStream (I-§2.13)
{
// Constructors
public FileInputStream(File file); §2.9.1
public FileInputStream(FileDescriptor fdObj); §2.9.2
public FileInputStream(String name); §2.9.3
// Methods
public int available(); §2.9.4
public void close(); §2.9.5
protected void finalize(); §2.9.6
public final FileDescriptor getFD(); §2.9.7
public int read(); §2.9.8
public int read(byte b[]); §2.9.9
public int read(byte b[], int off, int len); §2.9.10
public long skip(long n); §2.9.11
}
A file input stream is an input stream for reading data from a File (I-§2.7) or from a FileDescriptor (I-§2.8).
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 (I-§2.28)
- If the file is not found.
- Throws
- SecurityException (I-§1.43)
- If a security manager exists, its checkRead method (I-§1.15.19) is
called with the path name (I-§2.7.16) of this File argument to see if the
application is allowed read access to the file. This may result in a
security exception (I-§1.43).
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 (I-§1.43)
- If a security manager exists, its checkRead method (I-§1.15.18) 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 (I-§1.43).
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 (I-§1.15.19) 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 (I-§1.43).
- Parameters:
name
-
the system dependent file name
- Throws
- FileNotFoundException (I-§2.28)
- If the file is not found.
- Throws
- SecurityException (I-§1.43)
- If a security manager exists, its checkRead method (I-§1.15.19) 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
(I-§1.43).
available
public int available()
throws IOException
- Returns:
- the number of bytes that can be read from this file input stream without blocking.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- available in class InputStream (I-§2.13.2).
close
public void close()
throws IOException
- Closes this file input stream and releases any system resources associated
with the stream.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- close in class InputStream (I-§2.13.3).
finalize
protected void finalize()
throws IOException
- This finalize method ensures that the close method (I-§2.9.5) of this file
input stream is called when there are no more references to it.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- finalize in class Object (I-§1.12.4).
getFD
public final FileDescriptor getFD()
throws IOException
- Returns:
- the file descriptor object (I-§2.8) associated with this stream.
- Throws
- IOException (I-§2.29)
- 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.
- Returns:
- the next byte of data, or -1 if the end of the file is reached.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- read in class InputStream (I-§2.13.6).
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 is there is no more
data because the end of the file has been reached.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- read in class InputStream (I-§2.13.7).
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 is there is no more
data because the end of the file has been reached.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- read in class InputStream (I-§2.13.8).
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.
- Parameters:
n
-
the number of bytes to be skipped
- Returns:
- the actual number of bytes skipped.
- Throws
- IOException (I-§2.29)
- If an I/O error occurs.
- Overrides:
- skip in class InputStream (I-§2.13.10).
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com