java 判斷是否存在路徑,不存在自動創建(兼容 window 和 linux)


 1     private void createPath(String path){
 2         String os = System.getProperty("os.name");
 3         String tmpPath = path;
 4         //兼容 linux 系統
 5         if(os.toLowerCase().startsWith("win")){
 6             tmpPath = path.replaceAll("/", "\\\\");
 7         }
 8         //判斷路徑是否存在
 9         File filePath = new File(tmpPath);
10         if(!filePath.exists()){
11             //不存在,創建目錄
12             filePath.mkdirs();
13         }
14     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM