This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes create a file without directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "create a file without directory" Watch "create a file without directory" New topic
Author

create a file without directory

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
I want to create a file in this path C:\\test\\A\\B\\myfile.txt. But the directory A, B and file 'myfile.txt' all are not existed.

Do I have easiest way to directly create that file, instead of creating directory A, B first ?

Thanks.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://download-llnw.oracle.com/javase/6/docs/api/java/io/File.html#mkdirs()

The documentation is your friend.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20077
    
  30

But make sure you call that method on the parent file. If you call it on your current File object then you will create a folder with that name, and you can't create a file with the same name again until you remove the folder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create a file without directory
 
It's not a secret anymore!