首页 > 编程语言 > 详细

java 判断是否存在路径,不存在自动创建(兼容 window 和 linux)

时间:2021-02-03 10:22:38      阅读:23      评论:0      收藏:0      [点我收藏+]
 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     }

 

java 判断是否存在路径,不存在自动创建(兼容 window 和 linux)

原文:https://www.cnblogs.com/17years/p/14365153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!