Skip to content

Instantly share code, notes, and snippets.

@tai2
Created January 13, 2012 02:54
Show Gist options
  • Save tai2/1604340 to your computer and use it in GitHub Desktop.
Save tai2/1604340 to your computer and use it in GitHub Desktop.
Remove a file or directory including its contents recursively
import java.io.File;
import java.io.IOException;
public class Rmr {
public static void rmr(String path) {
File target = new File(path);
rmr(target);
}
public static void rmr(File target) {
if (target.isDirectory()) {
for (File entry : target.listFiles()) {
rmr(entry);
}
}
target.delete();
}
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("no file");
}
try {
rmr(args[0]);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment