Class: java.io.FileInputStream
- public class FileInputStream
- extends InputStream
FileInputStream obtains input bytes
from a file in a file system. What files
are available depends on the host environment.
FileInputStream is meant for reading streams of raw bytes
such as image data. For reading streams of characters, consider using
FileReader.
Inheritance
Superclass tree:- java.lang.Object
- java.io.InputStream
- java.io.FileInputStream
Methods
-
FileInputStreamtop
public FileInputStream(File file) throws FileNotFoundExceptionCreates aFileInputStreamby opening a connection to an actual file, the file named by theFileobjectfilein the file system. A newFileDescriptorobject is created to represent this file connection.First, if there is a security manager, its
checkReadmethod is called with the path represented by thefileargument as its argument.If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a
FileNotFoundExceptionis thrown. -
FileInputStreamtop
public FileInputStream(FileDescriptor fdObj)Creates aFileInputStreamby using the file descriptorfdObj, which represents an existing connection to an actual file in the file system.If there is a security manager, its
checkReadmethod is called with the file descriptorfdObjas its argument to see if it's ok to read the file descriptor. If read access is denied to the file descriptor aSecurityExceptionis thrown.If
fdObjis null then aNullPointerExceptionis thrown. -
FileInputStreamtop
public FileInputStream(String name) throws FileNotFoundExceptionCreates aFileInputStreamby opening a connection to an actual file, the file named by the path namenamein the file system. A newFileDescriptorobject is created to represent this file connection.First, if there is a security manager, its
checkReadmethod is called with thenameargument as its argument.If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a
FileNotFoundExceptionis thrown. -
availabletop
public native int available() throws IOExceptionReturns an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.In some cases, a non-blocking read (or skip) may appear to be blocked when it is merely slow, for example when reading large files over slow networks.
- Override hierarchy:
- available from InputStream
-
closetop
public void close() throws IOExceptionCloses this file input stream and releases any system resources associated with the stream.If this stream has an associated channel then the channel is closed as well.
- Override hierarchy:
- close from InputStream
-
finalizetop
protected void finalize() throws IOExceptionEnsures that theclosemethod of this file input stream is called when there are no more references to it. -
getChanneltop
public FileChannel getChannel()Returns the unique FileChannel object associated with this file input stream.The initial position
of the returned channel will be equal to the number of bytes read from the file so far. Reading bytes from this stream will increment the channel's position. Changing the channel's position, either explicitly or by reading, will change this stream's file position. -
getFDtop
public final FileDescriptor getFD() throws IOExceptionReturns theFileDescriptorobject that represents the connection to the actual file in the file system being used by thisFileInputStream. -
readtop
public native int read() throws IOExceptionReads a byte of data from this input stream. This method blocks if no input is yet available.- Override hierarchy:
- read from InputStream
-
readtop
public int read(byte[] b) throws IOExceptionReads up tob.lengthbytes of data from this input stream into an array of bytes. This method blocks until some input is available.- Override hierarchy:
- read from InputStream
-
readtop
public int read(byte[] b, int off, int len) throws IOExceptionReads up tolenbytes of data from this input stream into an array of bytes. Iflenis not zero, the method blocks until some input is available; otherwise, no bytes are read and0is returned.- Override hierarchy:
- read from InputStream
-
skiptop
public native long skip(long n) throws IOExceptionSkips over and discardsnbytes of data from the input stream.The
skipmethod may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0. Ifnis negative, anIOExceptionis thrown, even though theskipmethod of the java.io.InputStream superclass does nothing in this case. The actual number of bytes skipped is returned.This method may skip more bytes than are remaining in the backing file. This produces no exception and the number of bytes skipped may include some number of bytes that were beyond the EOF of the backing file. Attempting to read from the stream after skipping past the end will result in -1 indicating the end of the file.
- Override hierarchy:
- skip from InputStream
