简体   繁体   中英

dynamic path in java application

I want to specify the path dynamically. myapp/CopyFolder and myapp/RunFolder's are inside application like myapp/WEB-INF. The code I have given below is in .java file(in eclipse) and in .class file(in tomcat inside myapp/WEB-INF/classname/packagename/ ). My deployment is in tomcat.

 try {
        functionNamesObject.Integration(
                ".txt",
                path+"\\CopyFolder",
                path+"\\RunFolder",
                "app.exe",
                "Input.txt"
        );

I want path to be dynamic when I call above function. I tried with getResource("MyClass.class") , new File("").getAbsolutePath(); and System.getProperty("user.dir") but no use. Is there any other way?

You can get the path value as below:

URL resource = getClass().getResource("/");
String path = resource.getPath();

This will return the absolute path to to your myApp/WEB-INF/classes directory.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM