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
Post a Comment