| The code is as follows: |
Copy code |
File f = new File (".");
String absolutePath = f. getAbsolutePath ();
System. out. println (absolutePath ); |
1. Space in the path:
| The code is as follows: |
Copy code |
|
String pathtem = null;
URL ut = Thread. currentThread (). getContextClassLoader (). getResource ("");
Pathtem = ut. toString ();
Pathtem = pathtem. replace ("% 20 & Prime;," "); // remove spaces
Pathtem = pathtem. substring (6, pathtem. length (); // remove "file :/"
Return value:
D:/apache/webapps/Ev/WEB-INF/classes/
Obtain the path in struts
String rootuploadpath = this. getServlet (). getServletContext (). getRealPath ("/"); |
2. After the jar package is generated
| The code is as follows: |
Copy code |
String pathtem = null;
URL ut = Csssb_se.class.getResource ("");
Pathtem = ut. toString ();
Pathtem = pathtem. replace ("% 20 & Prime;," ");
Pathtem = pathtem. substring (0, pathtem. indexOf (projectname ));
Pathtem = pathtem. replace ("file :///","");
Pathtem = pathtem. replace ("file :/","");
Pathtem = pathtem. replace ("jar :",""); |
3. After the war package is generated, Tomcat
| The code is as follows: |
Copy code |
|
String Dirpath = null;
String Project_name = "TranData ";
URL ut = Thread. currentThread (). getContextClassLoader (). getResource ("");
Dirpath = ut. toString ();
Dirpath = Dirpath. replace ("% 20 & Prime;," ");
Dirpath = Dirpath. substring (6, Dirpath. length ());
Int project_name_index = Dirpath. indexOf (Project_name );
Dirpath = Dirpath. substring (0, project_name_index
+ Project_name.length () + 1 );
String xmlfilepath = Dirpath + "s. xml "; |