Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

making directories

Thread view: 
lowenbrau - 13 Aug 2007 09:31 GMT
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()


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.