FileReader class Read file in Java shows the resolution of FileNotFoundException exception

Source: Internet
Author: User

Recently looking at a letter of Java small software source code, and then try to write their own, but in the reading of the file has been found "file not found" exception, check the various environment variables and directories, finally found the problem. The following are the specific error conditions:

  

Import Java.io.FileReader;  Public class test{    publicstaticvoid    {        new FileReader (" A.txt ");        System.out.println (A.read ());}    }

The file system is compiled with an error:

Test.java:6: Error: Not reported exception error filenotfoundexception; must be captured or declared to throw         new filereader ("A.txt");                       ^Test.java:7: Error: Not reported exception error ioexception; it must be captured or declared to throw        System.out.println (A.read ());                                  ^

At the prompt, we throw an exception after calling the object's method signature, so the system doesn't get an error. Specific as follows:

Import Java.io.FileReader; Import java.io.IOException;  Public class test{    publicstaticvoidthrows  ioexception    {         New filereader ("A.txt");        System.out.println (A.read ());}    }

At this point the output of the program is:

97

That is, the character ' a '.

FileReader class Read file in Java shows the resolution of FileNotFoundException exception

Related Article

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.