System not able to find the specified file

前端 未结 2 1635
盖世英雄少女心
盖世英雄少女心 2021-01-25 02:57

I am trying to read from a file using Java. But it shows an error saying that system cannot find the specified file, when the file is lying in the same directory as the source f

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 03:08

    There is not problem in your code, its just that when you do not give any file location The System tries to find the file in the Project root.

    Check the image below:

    enter image description here

    EDIT: If you are using Eclipse, it should be like this. WHt dont you just paste a screenshot of your project directory.

    C:\CSMAIN\ws\TestFile\src\file.java

    C:\CSMAIN\ws\TestFile\RoomList.txt

    If you are not using any IDE then, you can create a project and put both the files in the project directory and compile it using command prompt and run it. It works.

提交回复
热议问题