FileInputStream

public class FileInputStream extends InputStream

An input stream that reads bytes from a file.

   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.

Public Constructor Summary

FileInputStream(File file)
Constructs a new FileInputStream that reads from file.
FileInputStream(FileDescriptor fd)
Constructs a new FileInputStream that reads from fd.
FileInputStream(String path)
Equivalent to new FileInputStream(new File(path)).

Public Method Summary

int
available()
Returns an estimate of the number of 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.
void
close()
Closes this input stream and releases any system resources associated with the stream.
FileChannel
getChannel()
Returns a read-only FileChannel that shares its position with this stream.
final FileDescriptor
getFD()
Returns the underlying file descriptor.
int
read()
Reads the next byte of data from the input stream.
int
read(byte[] buffer, int byteOffset, int byteCount)
Reads up to len bytes of data from the input stream into an array of bytes.
long
skip(long byteCount)
Skips over and discards n bytes of data from this input stream.

Protected Method Summary

void
finalize()
Ensures that all resources for this stream are released when it is about to be garbage collected.

Inherited Method Summary

Public Constructors

public FileInputStream (File file)

Constructs a new FileInputStream that reads from file.

Parameters
file the file from which this stream reads.
Throws
FileNotFoundException if file does not exist.

public FileInputStream (FileDescriptor fd)

Constructs a new FileInputStream that reads from fd.

Parameters
fd the FileDescriptor from which this stream reads.
Throws