Java create directories and delete files which should be directories

155 Views Asked by At

I want to create a directory path in Java using the File#mkdirs() method. Let's consider the path "example/example/example". new File("example/example/example").mkdirs() creates the directories. However, if new File("example/example").exists() && new File("example/example").isFile() invoking new File("example/example/example").mkdirs() does nothing and returns false. If (and only if) this case happens, I want that the file gets deleted and the directory path is created instead. Is there any solution to this problem or do I have to handle it by myself (iterating through the path)?

0

There are 0 best solutions below