Reputation: 1542
I have a .jar file called install.jar, which copies various file types to %appdata%/folder/abc/
What I need is a way to delete the files, either with the same jar or a new one, so I can reset the application for an update. I have looked on SO as well as google, and have found no answer.
If java doesn't let you delete folders, I need a way to delete all files inside of a folder, or at the very least, rename the folder.
Upvotes: 1
Views: 640
Reputation: 66
You could locate some useful information in this link. Which was previously asked.
Upvotes: 0
Reputation: 12837
// Deletes all files and subdirectories under dir.
// Returns true if all deletions were successful.
// If a deletion fails, the method stops attempting to delete and returns false.
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
Upvotes: 4