Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

java - 'System cannot find the specified file path' error - BlueJ

I'm creating a Quiz program in BlueJ where I read in my questions.csv file and then break them up into an array of objects.

My Question file is located in the same directory as both my package file, and my .class files. I have already tried specifiying the absolute path file (C://Users ...), and also tried using the .getAbsoluteFilePath() method. None have worked.

If anyone has any solutions as to how I can read in the file successfully, that would be much appreciated. Thank you.

Here is a screenshot of my project directory

Here is the section of my code which reads in the file

       String csv = "";
       String[] valueList = new String[4];
    
       // identify file
       String inputFile = ("questions.csv");
       // open file
       Scanner fileReader = new Scanner(new File(inputFile));
    
       // loop for every csv row, fetch from file and store
       for (int i = 0; i < questionList.length; i++) {
    
         csv = fileReader.nextLine();
         valueList = csv.split(",");
    
         // new instance of the Question class (record)
         questionList[i] = new Question(valueList[0], valueList[1], valueList[2], valueList[3], valueList[4]);
       }
    
       fileReader.close();
    } // end readQuestionFile()```



question from:https://stackoverflow.com/questions/66062389/system-cannot-find-the-specified-file-path-error-bluej

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...