0

I am trying to read a file called Inspirational_Quotes. The .txt file is in my eclipse workspace/project (the directory is fine). I am not sure why it is not being able to read/locate the file :

import java.io.*;
import java.util.Scanner;
public class TesterFinal {

    private int[] myData = new int[1000];

    public TesterFinal(String Inspirational_Quotes)
    {
        loadFile("Inspirational_Quotes");
    }

    public void loadFile(String Inspirational_Quotes)
    {
        int index = 0; 
        File file = new File(Inspirational_Quotes);
        try{
            Scanner inFile = new Scanner(file);
            while (inFile.hasNext())
            {
                myData[index] = inFile.nextInt();
                index++;
            }
        }
        catch(FileNotFoundException e) {
            System.out.println("File Not Found in Directory."); 
        }
    }

    public static void main(String[] args)
    {
        TesterFinal one = new TesterFinal("Inspirational_Quotes");
        //one.loadFile("Inspirational_Quotes");
    }

}
  • Is your file in the same directory as your class file? – PM 77-1 Feb 16 '18 at 21:53
  • Is the file name "Inspirational_Quotes" or "Inspirational_Quotes.txt" – FredK Feb 16 '18 at 21:53
  • Possible duplicate of [File not found error in java, file is in my project folder?](https://stackoverflow.com/questions/40930397/file-not-found-error-in-java-file-is-in-my-project-folder) – PM 77-1 Feb 16 '18 at 21:55
  • try absolute path. is it possible to add screen shot of project directory? Also use parameter which you have passed – VedantK Feb 17 '18 at 15:12

0 Answers0