How do I delete a directory that isn't empty?

Christopher Schultz

It's got to be a recursive-like method (in that it recurses the subdirs and deletes their contents, too). Something like this will probably work (off the top of my head):

import java.io.File;

public void nuke(File path)
   throws IOException
   File[] files = path.listFiles();

   for(int i=0; i<files.length; ++i)

You may want to do some more error checking, etc. but that should basically work.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact