java基礎

java獲取當前路徑的幾種 方法:
String property = System.getProperty("user.dir");//獲取當前項目路徑
System.out.println(property);
File file=new File(".");
try {
String canonicalPath = file.getCanonicalPath();//相對路徑
String ab=file.getAbsolutePath();//絕對路徑
System.out.println(canonicalPath);
System.out.println(ab);
} catch (IOException e) {
e.printStackTrace();
}
//通過類取得路徑
String path = Test1.class.getResource("/").getPath();
System.out.println(path);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章