-1

i can seem to understand why my code isn't compiling. Everytime I run it, I get a FILENOTFOUNDException. Any help would be much appreciated. :D

public static void main(String args[]) throws IOException 
    {

        Scanner diskScanner = 
                new Scanner(new File("EmployeeInfo.txt"));

        for(int empNum = 1; empNum<=3; empNum++)
        {
            payOneEmployee(diskScanner);
        }

    }
    static void payOneEmployee(Scanner aScanner)
    {
        Employee anEmployee = new Employee();

        anEmployee.setName(aScanner.nextLine());
        anEmployee.setJobTitle(aScanner.nextLine());
        anEmployee.cutCheck(aScanner.nextDouble());
        aScanner.nextLine();
    }
  • Show your file structure. That file should be located where compilation is done, if you are using eclipse or intellij it will be at your projects root directory – Toumash Jun 30 '15 at 21:39
  • For the record, new File() does not create a file. – SimplyPanda Jun 30 '15 at 21:40
  • You didn't really give us enough information to answer this properly (the exception is pretty self-explanatory - the file could not be found, but you didn't tell us anything about where this file is, or where you run this from, so how should we figure it out?), so I'm going to go ahead and say this is a duplicate of [java.io.FileNotFoundException: the system cannot find the file specified](http://stackoverflow.com/questions/19871955/java-io-filenotfoundexception-the-system-cannot-find-the-file-specified). – Bernhard Barker Jun 30 '15 at 22:01

1 Answers1

1

Basically the exception message means the filename you specified is not an existing file in executions directory.

EDIT[copied from my comment]
That file should be located where compilation is done, if you are using eclipse or intellij it should be at your projects root directory.
+ Because you are passing in a relative path and not an absolute one to the file, java is recognizing it as a relative to execution directory which is located where followin code points to.

To check what is that desired input files directory simply use getAbsolutePath() on that file.
For instance:

File input = new File("EmployeeInfo.txt");
System.out.println("Move .txt to dir:" + input.getAbsolutePath());
Scanner diskScanner = new Scanner(input);

Then move the source .txt file to that location

Toumash
  • 1,077
  • 11
  • 27