How can I find out why java.io.File.mkdir () returns false

How to find out why java.io.File.mkdir() returns false . I can create the directory manually.

UPDATE: My code is as follows:

 String directoryName = "C:/some/path/"; File directory= new File(directoryName ); if (!directory.exists() && !directory.mkdir()) { throw new RuntimeException("Failed to create directory: " + directoryName); } 
+4
source share
5 answers

You will need to use mkdirs() if the parent folder ( some in your example) does not exist yet.

+9
source

The answer is simple, you are trying to create subfolders (a folder inside a folder). For subfolders, use File.mkdirs() . It works, (verified).

+2
source

I don’t think you can, at least not with Java. Being what the OS makes this definition, Java simply delegates to it and returns the result.

Have you tried to make sure your File object indicates where you think?

Update: if C: / some does not exist, you must create it before you can create C: / some / path. Or use mkdirs () as indicated.

+1
source

If you use something like a process monitor for windows, you can see an OS level attempt to create a directory.

This may give you the information you need.

You probably need to use filters in the process monitor, because usually there is a lot of disk activity :)

+1
source

Using cygwin ?

mkdir may return false, but continue to create the folder anyway. A value of false only indicates that the folder does not yet exist.

You may need to try directory.exists() after calling mkdir() (or even mkdirs() )

0
source

Source: https://habr.com/ru/post/1414185/


All Articles