java - How to enter a directory as an argument in Eclipse -


basically, have directory files in it. in run configurations trying put directory arguement so: \(workspacename\directory. then, following code should create list of files in directory:

string directory = args[1]; file folder = new file(directory); file[] allfiles = folder.listfiles(); arraylist<file> properfiles = null; (file file: allfiles) {     if(file.getname().endswith(".dat")){     properfiles.add(file);     } } 

the problem i'm facing reason allfiles null.

i'll take guess @ problem might be:

if argument relative path (as opposed absolute path, staring "/" or "c:/" example), keep in mind files relative working directory of application.

so new file(directory) relative wherever application started. in eclipse default working directory in project. if project in top level of workspace, workspacename/project.

you can try printing out folder.getabsolutepath(), folder.exists() , folder.isdirectory() diagnose problem.


Comments

Popular posts from this blog

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -

asp.net - call stack missing info on mono with apache and mod_mono -