Path.createFile() and Path.createDirectory() throw NoSuchFileException if parent doesn't exist (Windows)
Alan Bateman
Alan.Bateman at Sun.COM
Tue Aug 25 11:59:15 PDT 2009
Vince Bonfanti wrote:
> I notice that on Windows both Path.createFile() and
> Path.createDirectory() throw a NoSuchFileException if their parent
> directory doesn't exist. Is this expected behavior for all file
> systems, or is it optional for a file system to create the parent
> directories if they don't exist? In either case, it should documented
> in the Javadocs.
>
> Vince
>
All of Path's createXXX method are specified to throw IOException if
they fail (a non-existent parent directory being one of many possible
reasons). Implementations can throw more specific exceptions where they
can detect specific errors and map them to a specific IOException. So if
the parent directory doesn't exist then the createXXX methods should
fail but it's up to the implementation if it throws more specific/useful
IOException or not. In this case, we attempt to map this case to
NoSuchFileException. Does that help? Where you need to create a file
tree then the Files.createDirectories utility method can be used.
-Alan.
More information about the nio-discuss
mailing list