Created
January 13, 2012 02:54
-
-
Save tai2/1604340 to your computer and use it in GitHub Desktop.
Remove a file or directory including its contents recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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