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     }

 

posted @ 2021-02-03 08:38  拾柒年  阅读(1473)  评论(0)    收藏  举报