java/struts/tomcat中的取路径的程序代码
代码如下 | 复制代码 |
File f = new File(“.”); String absolutePath = f.getAbsolutePath(); System.out.println(absolutePath); |
1.路径中空格:
代码如下 | 复制代码 |
String pathtem=null; struts中得到路径 |
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 xmlfilepath = Dirpath + “s.xml”; |
补充:Jsp教程,Java技巧及代码