Azulflame
Azulflame

Reputation: 1542

Deleting files using a .jar

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

Answers (2)

Ruser1510890
Ruser1510890

Reputation: 66

You could locate some useful information in this link. Which was previously asked.

Visit < Is there a quick way to delete a file from a Jar / war without having to extract the jar and recreate it?>

Upvotes: 0

Jiri Kremser
Jiri Kremser

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

Related Questions