当前位置:web 服务器 > Tomcat >>

java/struts/tomcat中的取路径的程序代码

 代码如下 复制代码
File f = new File(“.”);
String absolutePath = f.getAbsolutePath();
System.out.println(absolutePath);

1.路径中空格:

 代码如下 复制代码

String pathtem=null;
URL ut=Thread.currentThread().getContextClassLoader().getResource(“”);
pathtem=ut.toString();
pathtem=pathtem.replace(“%20″, ” “);//去掉空格
pathtem=pathtem.substring(6,pathtem.length());//去掉”file:/”
返回:
d:/apache/webapp/Ev/WEB-INF/classes/

struts中得到路径
String rootuploadpath = this.getServlet().getServletContext().getRealPath(“/”);

2.生成jar包后

 代码如下 复制代码
String pathtem=null;
URL ut=Csssb_se.class.getResource(“”);
pathtem=ut.toString();
pathtem=pathtem.replace(“%20″, ” “);
pathtem=pathtem.substring(0,pathtem.indexOf(projectname));
pathtem=pathtem.replace(“file:///”,”");
pathtem=pathtem.replace(“file:/”,”");
pathtem=pathtem.replace(“jar:”,”");

3.生成war包后,Tomcat

 代码如下 复制代码

String Dirpath = null;
String Project_name = “TranData”;
URL ut = Thread.currentThread().getContextClassLoader().getResource(“”);
Dirpath = ut.toString();
Dirpath = Dirpath.replace(“%20″, ” “);
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”;

补充:Jsp教程,Java技巧及代码 
Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,