InputStream objects created with the FileInputStream class can be used to read content from a file. The two commonly used constructors are as follows:
FileInputStream (String FilePath) FileInputStream (File fileobj)
Both constructors will throw filenotfoundexception exceptions. Where FilePath is the full pathname of the file, and Fileobj is the file object that describes it.
The following example creates two FileInputStream objects that use the same disk file, and are created using the two constructors, respectively:
FileInputStream F0 = new FileInputStream ("/autoexec.bat"); File F = new file ("/autoexec.bat"); FileInputStream f1 = new FileInputStream (f);
Although the first constructor may be more common, using the second constructor, you can use the method of the file class to further examine the file before attaching it to the input stream. When you create a FileInputStream object, you can also open the stream for reading. The FileInputStream class overrides the 6 methods in the InputStream abstract class, but does not rewrite the mark () and Reset () methods. An IOException exception is thrown when an attempt is made to call the Reset () method on a FileInputStream object.
As an example:
Explore Java IO's FileInputStream class