Application scenario: The file or directory to be manipulated is placed in a directory of the project, together with the project deployment management.
The easiest way to think of it is System.getproperty ("User.dir"), but this approach is different in terms of publishing and the address to eclipse, where the published Dynamic Web Project is System.getproperty (" User.dir ") value is: d:/eclipse/, for Eclipse is d:/workspace/test01/.
In this case, most of us want to get the root directory address of the Dynamic Web project, and finally get the root directory address.
public string Gettemplatepath () {
string root = Thread.CurrentThread (). Getcontextclassloader (). GetResource (""). ToString ();
System.out.println ("Gettemplatepath:--------" +root);
Return root.substring (Root.indexof ("file") + "file". Length () +2);
}
The value returned is d:/ide/apache-tomcat-6.0.43/wtpwebapps/devplatform/web-inf/classes/, and then the address is adjusted according to the location where the file/directory is located