File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes File.createNewFile(); File.mkdir(); order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File.createNewFile(); File.mkdir(); order" Watch "File.createNewFile(); File.mkdir(); order" New topic

File.createNewFile(); File.mkdir(); order

Brusk Baran
Ranch Hand

Joined: Nov 15, 2001
Posts: 132
I wonder why the following code does not work!

It just creates a file, but cannot convert the newly created file to a directory structure..
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Something can either be a file or directory, not both at the same time. There is no way to convert a file to a directory, short of deleting the file and creating a directory with the same name. What exactly are you trying to accomplish?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
If you're trying to create a new file, and (some of) the parent directory structure doesn't exist yet, you can try something like:

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: File.createNewFile(); File.mkdir(); order
It's not a secret anymore!