Example usage for java.io File delete

List of usage examples for java.io File delete

Introduction

In this page you can find the example usage for java.io File delete.

Prototype

public boolean delete() 

Source Link

Document

Deletes the file or directory denoted by this abstract pathname.

Usage

From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java

private static void deleteTasks() {
    File dir = TASK_DIR;/*w w w .j  ava 2  s  .co  m*/

    File[] toDelete = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            if (name.startsWith(MUTATION_TASK_PROJECT_FILE_PREFIX)) {
                return true;
            }
            return false;
        }

    });
    if (toDelete == null) {
        logger.info("Got no files to delete in directory" + dir);
        return;
    }
    for (File d : toDelete) {
        boolean delete = d.delete();
        if (delete) {
            logger.info("Deleted task: " + d);
        } else {
            logger.info("Could not delete task: " + d);
        }
    }
}

From source file:edu.stanford.muse.webapp.GroupsConfig.java

/** returns status of success */
public static boolean delete(String dir, String session) throws IOException, ClassNotFoundException {
    if (dir == null)
        return false;
    String filename = dir + File.separatorChar + session + GROUPING_SUFFIX;
    File f = new File(filename);
    if (!f.exists())
        return false; // empty result
    return f.delete();
}

From source file:Main.java

public static void copy(InputStream stream, String path) throws IOException {

    final File file = new File(path);
    if (file.exists()) {
        file.delete();
    }/* w  w w  .j a va  2s .c o m*/
    final File parentFile = file.getParentFile();

    if (!parentFile.exists()) {
        //noinspection ResultOfMethodCallIgnored
        parentFile.mkdir();
    }

    if (file.exists()) {
        return;
    }
    OutputStream myOutput = new FileOutputStream(path, true);

    byte[] buffer = new byte[1024];
    int length;
    while ((length = stream.read(buffer)) >= 0) {
        myOutput.write(buffer, 0, length);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    stream.close();

}

From source file:Main.java

public static void deleteFile(File oldPath) {
    if (oldPath.isDirectory()) {
        File[] files = oldPath.listFiles();
        for (File file : files) {
            deleteFile(file);//w w  w .ja v  a 2 s .  com
        }
    }
    oldPath.delete();
}

From source file:com.microsoftopentechnologies.windowsazurestorage.helper.CredentialMigration.java

/**
 *
 * Take the legacy local storage credential configuration and create an
 * equivalent global credential in Jenkins Credential Store
 *
 *///  w w  w .j  a v  a2s. c  om
private static void removeFile(String sourceFile) throws IOException {
    File file = new File(sourceFile);

    if (file.delete()) {
        LOGGER.log(Level.INFO, file.getName() + " is deleted!");
    } else {
        LOGGER.log(Level.WARNING, file.getName() + "deletion is failed.");
    }
}

From source file:com.wso2telco.services.bw.FileUtil.java

public static void deleteFile(String filename) {

    try {/*from ww w  .  j  a  va  2 s.c o  m*/
        File f1 = new File(filename);
        boolean success = f1.delete();
        if (!success) {
            //System.out.println("Deletion failed.");
            //System.exit(0);
        } else {
            //System.out.println("File deleted.");
        }
    } catch (Exception e) {

    }
}

From source file:Main.java

/**
 * delete files in directory/*  ww  w . jav a 2s.c om*/
 *
 * @param directory
 */
private static void deleteFilesInDirectory(File directory) {
    if (directory != null && directory.exists() && directory.isDirectory()) {
        for (File item : directory.listFiles()) {
            if (item.isDirectory()) {
                deleteFilesInDirectory(item);
            } else {
                item.delete();
            }
        }
    }
}

From source file:Main.java

public static boolean deleteRecursive(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory()) {
        for (File child : fileOrDirectory.listFiles()) {
            deleteRecursive(child);//from   w w w  .j a  v  a 2s .c o m
        }
    }
    return fileOrDirectory.delete() || !fileOrDirectory.exists();
}

From source file:ch.unibas.fittingwizard.infrastructure.base.ScriptUtilities.java

public static void deleteFileIfExists(File resultsFile) {
    if (resultsFile.exists()) {
        logger.info("Deleting existing file. " + FilenameUtils.normalize(resultsFile.getAbsolutePath()));
        if (resultsFile.delete()) {
            logger.info("File deleted.");
        } else {/*  w  w  w  .  j  av a  2 s  . c  om*/
            logger.error("Could not delete file.");
        }
    }
}

From source file:Main.java

public static boolean DeleteFile(File file) {
    if (file == null || !file.exists()) {
        return false;
    }/*from   w w  w.j  a  va 2 s  .  c  om*/
    if (file.isFile()) {
        return file.delete();
    }
    if (!file.isDirectory()) {
        return false;
    }
    File[] childFile = file.listFiles();
    if (childFile == null || childFile.length == 0) {
        return file.delete();
    }
    for (File f : childFile) {
        DeleteFile(f);
    }
    return file.delete();
}