I have a Business folder(e:\\Business) in this folder I have compiled file .I want use this folder in my main program .My main Program is in the Main folder(e:\\ProjectFile\\Main) .
I want get the path of Business folder dynamically .I use this statment but didn't work :
String loadedClassPath = System.getProperty("user.dir")+System.getProperty("file.separator")+"Business";
File operatorFile = new File(loadedClassPath);
URL operatorFilePath = operatorFile.toURL();
URL[] operatorFilePaths = new URL[]{operatorFilePath};
ClassLoader operatorsClassLoader = new URLClassLoader(operatorFilePaths);
Class[] operatorClass = new Class[]{ operatorsClassLoader.loadClass("Plus"), operatorsClassLoader.loadClass("Minus"),operatorsClassLoader.loadClass("Multiply") , operatorsClassLoader.loadClass("Divide") };
I think this part is not correct :
String loadedClassPath = System.getProperty("user.dir")+System.getProperty("file.separator")+"Business";
Can anyone help me?
Since "e:\\Business" is entirely unrelated to
you have to tell the program where/what it is.
Some options are:
main
. There are likely more options, but option 3 is very common, option 2 is less common but might be better choice depending on circumstances, and option 1 is highly discouraged.
Note: When constructing a path/file name, use new File(parent, child)
, or better yet, use the newer Paths.get(first, more, ...)
.
"Newer" refers to Java 7, meaning since July 28, 2011, so not really that new any more.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.