Java Utililty Methods Delete Temp Directory

List of utility methods to do Delete Temp Directory

Description

The list of methods to do Delete Temp Directory are organized into topic(s).

Method

voiddeleteTempDir()
Delete the temporary directory.
if (TEMP_DIR.exists()) {
    deleteDirectory(TEMP_DIR);
voiddeleteTempDir(File file)
delete Temp Dir
if (!cTempFiles.remove(file)) {
    return;
recursiveDelete(file);
voiddeleteTempDirectories(List lstTempDirectories)
delete Temp Directories
for (String file : lstTempDirectories) {
    System.out.println("Need to delete dir: " + file);
    deleteDir(new File(file));
voiddeleteTempDirectory(File dir)
delete Temp Directory
deleteDirectoryContents(dir);
boolean success = dir.delete();
if (!success) {
    throw new IOException();
voiddeleteTempMapset(String mapsetFolder)
Deletes the location and mapset(s) for GRASS data processing.
if ((mapsetFolder != null) && (mapsetFolder.length() > 2)) {
    String tmpFolder = new String(mapsetFolder.substring(0, mapsetFolder.lastIndexOf(File.separator)));
    if (new File(tmpFolder).exists()) {
        deleteDirectory(new File(tmpFolder));
voiddeleteTemporaryDirectory(String dir)
delete Temporary Directory
File tmpDir = new File(dir);
for (File f : tmpDir.listFiles()) {
    f.delete();
tmpDir.delete();
File tmpParentDir = tmpDir.getParentFile();
if (tmpParentDir.isDirectory() && tmpParentDir.getName().equals("tmp")) {
    tmpParentDir.delete();
...
voiddeleteTestData()
delete Test Data
File fileToDelete = new File(testFileLocation);
fileToDelete.delete();
voiddeleteTestDir(final File file)
delete Test Dir
if (file.isDirectory()) {
    File[] filesToDelete = file.listFiles();
    if (filesToDelete != null) {
        for (File f : filesToDelete) {
            deleteTestDir(f);
if (!file.delete()) {
    throw new RuntimeException("Failed to clean up after test");
voiddeleteTestDirectory(File testDir)
delete Test Directory
delete(testDir);
testDir.getParentFile().delete(); 
voiddeleteTestFile(String fileName)
Deletes the test file.
File testFile = new File(fileName);
if (testFile.exists()) {
    if (!testFile.delete()) {
        throw new RuntimeException("Test file " + fileName + " could not be deleted!");