public class SystemPath {
/**
* 获取当前项目的路径
* @return
*/
public static String getSysPath()
{
String path= Thread.currentThread().getContextClassLoader().getResource("").toString();
String temp=path.replaceFirst("file:/", "").replaceFirst("WEB-INF/classes/", "").replaceFirst("WebRoot/", "");
String separator= System.getProperty("file.separator");
String resultPath=temp.replaceAll("/", separator+separator);
return resultPath;
}
/**
*
* @return
*/
public static String getClassPath()
{
String path= Thread.currentThread().getContextClassLoader().getResource("").toString();
String temp=path.replaceFirst("file:/", "");
String separator= System.getProperty("file.separator");
String resultPath=temp.replaceAll("/", separator+separator);
return resultPath;
}
/**
* 获取当前临时目录
* @return
*/
public static String getSystempPath()
{
return System.getProperty("java.io.tmpdir");
}
/**
* 以\分割
* @return
*/
public static String getSeparator()
{
return System.getProperty("file.separator");
}
public static void main(String[] args){
System.out.println(getSysPath());
System.out.println(getSystempPath());
System.out.println(getSeparator());
System.out.println(getClassPath());
}
}