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