java - How to get file path dynamically? -
i write application load other classes other folder :
public static void main(string[] args) throws exception { string rootpath = null; rootpath = system.getproperty("user.dir"); //system.out.println(rootpath); file operatorfile = new file(rootpath + "business\\"); url operatorfilepath = operatorfile.tourl(); url[] operatorfilepaths = new url[]{operatorfilepath}; classloader cl = new urlclassloader(operatorfilepaths); // plus , minus,multiply,divide classes in business folder class[] operatorclass = new class[]{ cl.loadclass("plus"), cl.loadclass("minus"),cl.loadclass("multiply") , cl.loadclass("divide") };
i want dynamically business folder path(my main class in myfolder). both myfolder , business folders in drive d:\ . app dose not work because think below statement dose not correct :
file operatorfile = new file(rootpath + "business\\");
can me?
since have remeber points .
- where home drive pointed :
system.getproperty("user.home");
//either c or d whatever .
or :
rootpath = system.getproperty("user.dir")+system.getproperty("file.separator")+"business";
or
string rootpath = system.getproperty("user.dir")+system.getproperty("file.separator")+"d"+system.getproperty("file.separator")+"myfolder"; rootpath=rootpath.replaceall("myfolder", "");//remove myfolder url rootpath=rootpath+"business";//add business on url system.out.println(""+rootpath);//print file path
that return home directory business folder
Comments
Post a Comment