aspose file tools*
The moose likes I/O and Streams and the fly likes How to Delete a 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 » I/O and Streams
Bookmark "How to Delete a Directory" Watch "How to Delete a Directory" New topic
Author

How to Delete a Directory

Abdul Salam
Greenhorn

Joined: Feb 25, 2002
Posts: 10
Is there any reliable way of deleting a directory
and it's contents from java (recursively).
I have tried

It also did not work.My OS is win 2000 server.
Thx in advance.


Knowledge Xchange. SCJ2P.
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
I think u'll have to delete it thro' coding methods.U can write a method that accepts the directory path,using this delete the files of the current directory ,in case of sub-folders call this funtion recursively with the sub-folder path.This is the way I know.
Happy middling with java.
Netharam.
etrivelli nainar
Greenhorn

Joined: Feb 14, 2002
Posts: 5
So, can we delete a file using java I/O?
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Netharam's right. You have to delete all the files in the directory before deleting the directory itself. The methods in the File class isDirectory(), listFiles(), and delete() should be all you need.
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
FAQ: How do I delete a directory that isn't empty?
http://www.jguru.com/faq/view.jsp?EID=705646
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Delete a Directory
 
Similar Threads
How can a program point to a a different directory
Where in Javawebserver2.0 should I place my Html , Jsp and Java programs
NX: How to use javadoc
main method without public modifier
WA #1.....word association