java - Why can't I find my File? -
i'm trying open csv file name "logger.csv" have saved in source folder itself.
public static void main(string[] args) { string filename = "logger.csv"; file motor_readings = new file(filename); try { scanner inputstream = new scanner(motor_readings); while (inputstream.hasnext()){ system.out.println(inputstream.next()); } inputstream.close(); } catch (filenotfoundexception e) { system.out.println("error: file not found!"); } }
however, keeps on giving me "file not found" error.
if use relative pathing right - file needs exist in project root, not in directory of java file.
consider hierarchy:
project/ src/main/java file.java logger.csv
new file("logger.csv")
not work.
project/ logger.csv src/main/java file.java
new file("logger.csv")
now work. (notice, file adjacent src directory.)
Comments
Post a Comment