Exception in thread “main” java.io.FileNotFoundException: Error

前端 未结 4 1244
旧巷少年郎
旧巷少年郎 2020-11-30 12:30

I am using Eclipse to compile and run my java codes.

Here is Error I am getting.

Exception in thread \"main\" java.io.FileNotFoundEx         


        
4条回答
  •  醉梦人生
    2020-11-30 13:33

    Your file should directly be under the project folder, and not inside any other sub-folder.

    So, if your project folder is MyProject, it's folder structure(not complete though) should be like: -

    MyProject +- src +
              |      |
              |      +-- Your source file
              +- file.txt
    

    It should not be under src folder.


    Or, you can give the following path relative to the project folder to search for file in the src folder: -

    new File("src/file.txt");
    

提交回复
热议问题