java - mkdirs() return value for already existing directories -
file.mkdirs javadocs:
public boolean mkdirs()
creates directory named abstract pathname, including necessary nonexistent parent directories. note if operation fails may have succeeded in creating of necessary parent directories.
returns: true if , if directory created, along necessary parent directories; false otherwise
my question is: mkdirs() return false if of directories wanted create existed? or return true if successful in creating entire path file, whether or not directories existed?
it returns false.
from java doc: - true if directory created, false on failure or if directory existed.
you should this:
if (file.mkdirs()) { system.out.format("directory %s has been created.", file.getabsolutepath()); } else if (file.isdirectory()) { system.out.format("directory %s has been created.", file.getabsolutepath()); } else { system.out.format("directory %s not created.", file.getabsolutepath()); }
Comments
Post a Comment