Path File URI Resource

  • Path 通過 normalize toRealPath 來消除 “.” "…"toRealPath 與toAbsolutePath normalize 類似
Path curDir = Paths.get(".");
//Files 確認Path是否存在
boolean b = Files.exists(curDir,new LinkOption[]{LinkOption.NOFOLLOW_LINKS});
//消除". or.."
curDir.toAbsolutePath().normalize();

System.out.println(curDir.toRealPath());
//path 可以互相轉化 file
File file = curDir.toFile();
Path path = file.toPath();
//Path 轉化 uri 
URI  uri = curDir.toUri();


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章