1. 程式人生 > >java獲取專案絕對路徑

java獲取專案絕對路徑

public static String getTempPath(Class cls) {
String fileDir = "";
Properties prop = System.getProperties();
String os = prop.getProperty("os.name");
if (os.startsWith("win") || os.startsWith("Win")) {
fileDir = cls.getResource("/").toString().replace("file:/", "");
} else {
fileDir = "/"
+ cls.getResource("/").toString().replace("file:/", "");
}
return fileDir;

}

說明:不適用掛載專案的路徑獲取