Is there a proper way to check for file/directory existence in Java?

后端 未结 4 1850
不思量自难忘°
不思量自难忘° 2021-01-12 23:15

Code:

String dir = //Path to the  directory
File saveDir = new File(dir);
//Here comes the existence check
if(!saveDir.exists())
  saveDir.         


        
4条回答
  •  囚心锁ツ
    2021-01-12 23:43

    Just make the call to mkdirs. It will not overwrite existing directories so really, your check is unecessary (and in any case, unreliable).

提交回复
热议问题