This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Delete Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Delete Directory" Watch "Delete Directory" New topic
Author

Delete Directory

bob morkos
Ranch Hand

Joined: Sep 06, 2001
Posts: 104
How do you write a java application that deletes a directory. An example would help a lot. And is it posible to read the size of a file in a java program. Thanks.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The File class has methods delete() and length() which accomplish what you need.


"I'm not back." - Bill Harding, Twister
Spencer J Lee
Ranch Hand

Joined: Mar 19, 2003
Posts: 30
Hello,
I noticed that the delete method of the File class can only delete a directory if its empty. Is there an existing way or method to recursively delete a directory, its subdirectories, and files (i.e. rm -rf)? Or is this something I'll need to put together myself.
Thanks ahead of time.
Spencer
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Originally posted by Spencer Lee:
Hello,
...Or is this something I'll need to put together myself.

Yup
 
Consider Paul's rocket mass heater.
 
subject: Delete Directory
 
Similar Threads
Creating Directories using Servlet
Where in Javawebserver2.0 should I place my Html , Jsp and Java programs
cannot import package
creation of new directory inside an exisiting directory
db2jcc.jar