Reputation: 2741
I have current working file's directory path I:\apache-tomcat-7.0.40\webapps\ExecutableFileProcess\WEB-INF\classes\PackageName\
I want path like I:\apache-tomcat-7.0.40\webapps\ExecutableFileProcess\
. How can I do this in java code?
Upvotes: 0
Views: 2148
Reputation: 2040
You better get your App-Path from the ServletContext
in Servlet-Containern like Tomcat.
Use
servletContext.getRealPath(".");
// will return 'I:\apache-tomcat-7.0.40\webapps\ExecutableFileProcess\' on win.
// will return '/usr/local/tomcat/webapps/ExecutableFileProcess' on unix.
Upvotes: 1
Reputation: 295
Try this:
Path aPath = Paths.get("I:\\apache-tomcat-7.0.40\\webapps\\ExecutableFileProcess\\WEB-INF\\classes\PackageName\\");
Path parentsParentpath = aPath.getParent().getParent();
Upvotes: 0
Reputation: 2925
Have a look at
http://developer.android.com/reference/java/io/File.html#getParentFile()
Applying this twice will probably get you the right directory.
But note that you program might or might not be allowed to go there, based on the settings in the file system and the context your code runs in.
Upvotes: 0