Java判断文件夹是否存在,不存在则新建

Java判断是否存在文件夹,不存在则新建

File file=new File("C:/Users/QPING/Desktop/log.txt");    
if (!file.getParentFile().exists()) {
  file.getParentFile().mkdirs();
}

判断是否存在文件,不存在则新建

File file = new File("C:/Users/QPING/Desktop/log.txt");
if (!file.exists()) {
   file.createNewFile();
}
发布了156 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_42590334/article/details/103729063