Explore Java IO's FileInputStream class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.