Reputation: 127
What is the difference between file.mkDir()
and Files.createDirectory(path)
.
Is there any cases which suites better for any of them? Or Files.createDirectory(path)
is just newer version of file.mkDir()
(from newer Java version?
Thanks in advance.
Upvotes: 8
Views: 5003
Reputation: 7330
The difference is described in java docs.
file.mkDir()
:
- Creates the directory named by this abstract pathname.
- @return
true
if and only if the directory was created;false
otherwise
Files.createDirectory(path)
:
- Creates a new directory. The check for the existence of the file and the creation of the directory if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the directory. The {@link #createDirectories createDirectories} method should be used where it is required to create all nonexistent parent directories first.
The {@code attrs} parameter is optional {@link FileAttribute file-attributes} to set atomically when creating the directory. Each attribute is identified by its {@link FileAttribute#name name}. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored.
- @return the directory
Upvotes: 6