How do I find out why java.io.File.mkdir()
returns false
.
I can create the directory manually.
UPDATE: My code looks like this:
String directoryName = "C:/some/path/";
File directory= new File(directoryName );
if (!directory.exists() && !directory.mkdir()) {
throw new RuntimeException("Failed to create directory: " + directoryName);
}
You will need to use mkdirs()
if the parent folder (some
in your example) doesn't already exist.
The answer is simple, you're trying to create nested folders (a folder inside a folder). For nested folders use File.mkdirs()
. That works, (tested).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With