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

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -