File not found exception in Java code?
From the following code inside while loop following the equal sign My business is given the error that this file can not be found.Since We are of course finding the file learn in through the user I’m unclear why it can be giving me personally this error
tranfer java.io.Document;
tranfer java.io.FileNotFoundException;
tranfer java.io.IOException;
tranfer java.util.Code reader;
arrest class StatDriver
arrest static void main (String args)throws IOException
Code reader scan = innovative Scanner (System.in);
last int WIDTH = 10;
int count number = 0;
Stringed fileName;
two bottle grades = innovative doubleSIZE;
Specifi statistics = innovative Stat(grades, count);
Procedure.out.print(” Enter file label:”);
fileName = search within.next();
readFile(fileName, grades);
Procedure.out.println(“\n My personal Grades – View Statistics\n ————————-“);
Procedure.out.println(” Count number:” +statistics.getCount());
Procedure.out.println(” Regular:” +statistics.calcAvg());
Procedure.out.println(” Typical:” +statistics.calcMedian());
Procedure.out.println(” Maximum:” +statistics.findMax());
Procedure.out.println(” Minimum amount:” +statistics.findMin());
exclusive static void readFile(String fileName, two bottle grades)
last int WIDTH = 10;
Code reader inFile = null;
for(int my spouse and i = 0; my spouse and i < WIDTH; i++)
inFile = different Scanner(new File( fileName ));
while(inFile.hasNextDouble())
gradesi = inFile.nextDouble();
i++;
inFile.close();
FileNotFoundException generally is that — the particular file would not want to be determined.You can try outputting your file name to find out what report you’re trying to open.
Feasible ways your code may possibly fail:
:User sorts in wrong filename
– Filename/path carries a space inside it
It implies it can’t have the file which is being came into.
Test the transliteration, case, and path to be sure it’s correct.Try inputting all of the path if that does not work properly try getting into it covered in prices.The entire path is essential if that file becoming entered is just not in exactly the same directory because your class file.
If next to nothing works attempt hard coding some sort of file you already know exists and give it a try.
Leave a Reply
You must be logged in to post a comment.