System not able to find the specified file

前端 未结 2 1637
盖世英雄少女心
盖世英雄少女心 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.

    0 讨论(0)
  • 2021-01-25 03:28

    You should escape the slashes, try changing your code to:

    br = new BufferedReader(new FileReader("C:\\semester 2\\java\\PROJECTS\\BookingSystem\\file.java"));
    
    0 讨论(0)
提交回复
热议问题