Saphyra
Saphyra

Reputation: 460

How to determinate if a non-existing file is a directory?

File.isDirectory() "returns true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise"

Hovewer I need to know if the file is a directory BEFORE I create it.

How to?

Upvotes: 0

Views: 128

Answers (1)

Krystian G
Krystian G

Reputation: 2941

In java File represents either file or directory. You don't know what it is when it doesn't exist. When you have:

 File newFile = new File("C:\\name");

You can create either directory:

 newFile.mkdir();

OR file:

 newFile.createNewFile();

Upvotes: 1

Related Questions