dsa

Java FileInputStream Class

In this tutorial, we will learn about Java FileInputStream and its methods with the help of examples.

Java FileInputStream class obtains input bytes from a file. It is used for reading byte-oriented data (streams of raw bytes) such as image data, audio, video etc. You can also read character-stream data. But, for reading streams of characters, it is recommended to use FileReader class.

The FileOutputStream class is the subclass of the Java OutputStream.

Constructor and Description

Java FileInputStream class declaration

public class FileInputStream extends InputStream  

Class Methord

Sr.No. Method & Description
1 int available()

This method returns 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.

2 void close()

This method closes this file input stream and releases any system resources associated with the stream.

3 protected void finalize()

This method ensures that the close method of this file input stream is called when there are no more references to it.

4 FileChannel getChannel()

This method returns the unique FileChannel object associated with this file input stream.

5 FileDescriptor getFD()

This method returns the FileDescriptor object that represents the connection to the actual file in the file system being used by this FileInputStream.

6 int read()

This method reads a byte of data from this input stream.

7 int read(byte[] b)

This method reads up to b.length bytes of data from this input stream into an array of bytes.

8 int read(byte[] b, int off, int len)

This method reads up to len bytes of data from this input stream into an array of bytes.

9 long skip(long n)

This method skips over and discards n bytes of data from the input stream.