Hi,
I have encountered something interesting. In order to create a directory within another directory, the parent directory must be created first. For example:
File f = new File ("parent directory/child directory");
f.mkdir();
DOES NOT WORK
File f = new File ("parent directory");
f1.mkdir();
f = new File ("parent directory/child directory");
f.mkdir();
THIS WORKS
QUESTION:
is there a way to do it without explicitly creating the parent directory first?
Cheers
ST
Pushkaraj - 13 Aug 2007 09:39 GMT
> Hi,
>
[quoted text clipped - 18 lines]
> Cheers
> ST
If you scan File api neatly you could see a function
boolean mkdirs() : Creates the directory named by this abstract
pathname, including any necessary but nonexistent parent directories.
use this.
Thomas Kellerer - 13 Aug 2007 09:40 GMT
> is there a way to do it without explicitly creating the parent directory
> first?
Quote from:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#mkdirs()
"Creates the directory named by this abstract pathname, including any
necessary but nonexistent parent directories."
Thomas
Thomas Fritsch - 13 Aug 2007 09:43 GMT
lowenbrau schrieb:
> I have encountered something interesting. In order to create a directory
> within another directory, the parent directory must be created first.
[quoted text clipped - 16 lines]
> is there a way to do it without explicitly creating the parent directory
> first?
As always the Java API docs are a good for such questions.
Look up <http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html>
Carefully read about mkdir() and mkdirs().

Signature
Thomas
Andrew Thompson - 13 Aug 2007 09:47 GMT
...
>I have encountered something interesting.
Interesting to people who code by typing random
statements into an editor, rather than those who
consult the documentation first, perhaps..
>...In order to create a directory within another directory, the parent directory must be created first.
Un-huh..
>is there a way to do it without explicitly creating the parent directory first?
1st you might try RTFM.
<http://java.sun.com/javase/6/docs/api/java/io/File.html#mkdirs()>

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Ian Wilson - 13 Aug 2007 09:54 GMT
> Hi,
>
[quoted text clipped - 6 lines]
>
> DOES NOT WORK
Have you read the documentation for File.mkdir() and File.mkdirs()?
http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#mkdir()
>
> File f = new File ("parent directory");
[quoted text clipped - 9 lines]
> first?
>
Yes. File.mkdirs()