|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
java.io.FileInputStream
public class FileInputStream
This class is a stream that reads its bytes from a file.
| Constructor Summary | |
|---|---|
FileInputStream(File file)
This method initializes a FileInputStream to read from the
specified File object. |
|
FileInputStream(FileDescriptor fdObj)
This method initializes a FileInputStream to read from the
specified FileDescriptor object. |
|
FileInputStream(String name)
This method initializes a FileInputStream to read from the
specified named file. |
|
| Method Summary | |
|---|---|
int |
available()
This method returns the number of bytes that can be read from this stream before a read can block. |
void |
close()
This method closes the stream. |
protected void |
finalize()
finalize may be called by the memory management of the virtual machine when it determined that this instance's memory is unreachable and can be reclaimed. |
FileChannel |
getChannel()
This method creates a java.nio.channels.FileChannel. |
FileDescriptor |
getFD()
This method returns a FileDescriptor object representing the
underlying native file handle of the file this stream is reading
from |
int |
read()
This method reads an unsigned byte from the input stream and returns it as an int in the range of 0-255. |
int |
read(byte[] buf)
This method reads bytes from a stream and stores them into a caller supplied buffer. |
int |
read(byte[] buf,
int offset,
int len)
This method read bytes from a stream and stores them into a caller supplied buffer. |
long |
skip(long numBytes)
This method skips the specified number of bytes in the stream. |
| Methods inherited from class java.io.InputStream |
|---|
mark, markSupported, reset |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileInputStream(String name)
throws FileNotFoundException
FileInputStream to read from the
specified named file. A security check is first made to determine
whether or not access to this file is allowed. This is done by
calling the checkRead() method of the
SecurityManager
(if one exists) with the name of this file. An exception is thrown
if reading is not allowed. If the file does not exist, an exception
is also thrown.
name - The name of the file this stream should read from
SecurityException - If read access to the file is not allowed
FileNotFoundException - If the file does not exist
or if it is a directory
public FileInputStream(File file)
throws FileNotFoundException
FileInputStream to read from the
specified File object. A security check is first
made to determine
whether or not access to this file is allowed. This is done by
calling the checkRead() method of the
SecurityManager
(if one exists) with the name of this file. An exception is thrown
if reading is not allowed. If the file does not exist, an exception
is also thrown.
file - The File object this stream should read from
SecurityException - If read access to the file is not allowed
FileNotFoundException - If the file does not exist
or if it is a directory.public FileInputStream(FileDescriptor fdObj)
FileInputStream to read from the
specified FileDescriptor object. A security
check is first made to
determine whether or not access to this file is allowed. This is done by
calling the checkRead() method of the
SecurityManager
(if one exists) with the specified FileDescriptor
An exception is
thrown if reading is not allowed.
fdObj - The FileDescriptor object this stream
should read from
SecurityException - If read access to the file is not allowed| Method Detail |
|---|
public int available()
throws IOException
This method returns the number of unread bytes remaining in the file if the descriptor being read from is an actual file. If this method is reading from a ''special'' file such a the standard input, this method will return the appropriate value for the stream being read.
Be aware that reads on plain files that do not reside locally might possibly block even if this method says they should not. For example, a remote server might crash, preventing an NFS mounted file from being read.
available in class InputStreamIOException - If an error occurs
public void close()
throws IOException
close in interface Closeableclose in class InputStreamIOException - If an error occurs.
protected void finalize()
throws IOException
ObjectNOTE: The use of finalize() is strongly discouraged for realtime or safety-critical code. This method should only be used for debugging purposes. If used as a last resort to reclaim non-memory resouces, finalize() should indicate the resource leak with a loud error message.
There is no guarantee that finalize() will be called, the memory management may decide not to reclaim this object's memory or to delay the call to finalize() to an unspecified point in time. It is therefore recommended never to use the finalize method to release any resources (files, network connections, non-Java memory, etc.) since releasing of these resource may be delayed perpetually.
The order of finalization is not specified, i.e., the finalize method of any two objects that become unreachable may be called in an arbitrary order. It therefore has to be assumed that when finalize() is called on an object, that the finalize() method of any object that is only reachable through this object() has been called as well or is called simultaneously by another thread.
The presence of a finalize-method in any sub-class of Object causes the reclamation of the memory of this object to be delayed until the finalize() method has been executed. The finalize() method is typically executed by the finalizer thread (that may run at a low priority) or by a call to Runtime.runFinalization().
Any code sequence that creates instances of a class that defines a finalize() method must therefore ensure that sufficient CPU time is allocated to the finalizer thread or that Runtime.runFinalization() is called regularly such that the finalize() methods can be executed and the object's memory can be reclaimed.
The finalize method itself should never block or run for long times since it would otherwise block the finalizer thread or the thread that called Runtime.runFinalization() and prevent the execution other finalize() method and consequently prevent the reclamation of these object's memory.
For objects that are allocated in a javax.realtime.ScopedMemory, the finalize() methods will be called when this scoped memory is exited by the last thread. Unlike HeapMemory, which is controlled by the garbage collector, ScopedMemory provides a defined execution point for the finalize() mehods and it is therefore safer to use finalize() here.
finalize in class ObjectIOException
public final FileDescriptor getFD()
throws IOException
FileDescriptor object representing the
underlying native file handle of the file this stream is reading
from
FileDescriptor for this stream
IOException - If an error occurs
public int read()
throws IOException
This method will block until the byte can be read.
read in class InputStreamIOException - If an error occurs
public int read(byte[] buf)
throws IOException
This method will block until some data can be read.
This method operates by calling an overloaded read method like so:
read(buf, 0, buf.length)
read in class InputStreambuf - The buffer into which the bytes read will be stored.
IOException - If an error occurs.
public int read(byte[] buf,
int offset,
int len)
throws IOException
offset into
the buffer and attempts to read len bytes. This method can
return before reading the number of bytes requested. The actual number
of bytes read is returned as an int. A -1 is returned to indicate the
end of the stream.
This method will block until some data can be read.
read in class InputStreambuf - The array into which the bytes read should be storedoffset - The offset into the array to start storing byteslen - The requested number of bytes to read
IOException - If an error occurs.
public long skip(long numBytes)
throws IOException
skip in class InputStreamnumBytes - The requested number of bytes to skip
IOException - If an error occurspublic FileChannel getChannel()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||