Why can't I find my File?

前端 未结 3 1214
难免孤独
难免孤独 2021-01-28 00:01

I\'m trying to open a CSV file name \"logger.csv\" which I have saved in the source folder itself.

public static void main(String[] args) {
    String filename =         


        
相关标签:
3条回答
  • 2021-01-28 00:40

    To see where the file is expected update the code in your catch clause to:

            System.out.println("Error: File not found: " + motor_readings.getAbsolutePath());
    

    Put it there and be sure to refresh your workspace in Eclipse so that the file can be seen.

    0 讨论(0)
  • 2021-01-28 00:41

    Put the file on level up. In the main folder of the project.

    0 讨论(0)
  • 2021-01-28 00:51

    If you use relative pathing as you are right now - the file needs to exist in the project root, not in the directory of the java file.

    Consider this hierarchy:

    project/
      src/main/java
        file.java
        logger.csv
    

    new File("logger.csv") will not work.

    project/
      logger.csv
      src/main/java
        file.java
    

    new File("logger.csv") will now work. (notice, the file is adjacent to the src directory.)

    0 讨论(0)
提交回复
热议问题