public class FileInputStream
extends java.io.InputStream
implements java.io.Closeable
File file = ...
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
...
} finally {
if (in != null) {
in.close();
}
}
This stream is not buffered. Most callers should wrap this
stream with a BufferedInputStream.
Use FileReader to read characters, as opposed to bytes, from a file.
BufferedInputStream,
FileOutputStream| Constructor and Description |
|---|
FileInputStream(File file)
Constructs a new
FileInputStream that reads from file. |
FileInputStream(FileDescriptor fd)
Constructs a new
FileInputStream that reads from fd. |
FileInputStream(java.lang.String path)
Equivalent to
new FileInputStream(new File(path)). |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
protected void |
finalize()
Ensures that all resources for this stream are released when it is about
to be garbage collected.
|
IOCipherFileChannel |
getChannel()
Returns a read-only
IOCipherFileChannel that shares its position
with this stream. |
FileDescriptor |
getFD()
Returns the underlying file descriptor.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] buffer,
int byteOffset,
int byteCount) |
static int |
readSingleByte(java.io.InputStream in) |
long |
skip(long byteCount) |
public FileInputStream(File file) throws java.io.FileNotFoundException
FileInputStream that reads from file.file - the file from which this stream reads.java.io.FileNotFoundException - if file does not exist.public FileInputStream(FileDescriptor fd)
FileInputStream that reads from fd.fd - the FileDescriptor from which this stream reads.java.lang.NullPointerException - if fd is null.public FileInputStream(java.lang.String path)
throws java.io.FileNotFoundException
new FileInputStream(new File(path)).java.io.FileNotFoundExceptionpublic int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionprotected void finalize()
throws java.io.IOException
finalize in class java.lang.Objectjava.io.IOException - if an error occurs attempting to finalize this
stream.public IOCipherFileChannel getChannel()
IOCipherFileChannel that shares its position
with this stream.public final FileDescriptor getFD() throws java.io.IOException
java.io.IOExceptionpublic static int readSingleByte(java.io.InputStream in)
throws java.io.IOException
java.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] buffer,
int byteOffset,
int byteCount)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic long skip(long byteCount)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOException