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:Main.java

public static boolean deleteFile(String path) {
    boolean result = false;
    if (!TextUtils.isEmpty(path)) {
        File file = new File(path);
        if (file.exists()) {
            if (file.isFile()) {
                result = file.delete();
            } else {
                result = removeDir(file);
            }//w  w w  .j  av a 2 s  . c om
        }
    }
    return result;
}

From source file:nl.knaw.dans.easy.sword2examples.ContinuedDeposit.java

public static URI depositPackage(File bagDir, IRI colIri, String uid, String pw, int chunkSize)
        throws Exception {
    // 0. Zip the bagDir
    File zipFile = new File(bagDir.getAbsolutePath() + ".zip");
    zipFile.delete();
    Common.zipDirectory(bagDir, zipFile);

    // 1. Set up stream for calculating MD5
    FileInputStream fis = new FileInputStream(zipFile);
    MessageDigest md = MessageDigest.getInstance("MD5");
    DigestInputStream dis = new DigestInputStream(fis, md);

    // 2. Post first chunk bag to Col-IRI
    CloseableHttpClient http = Common.createHttpClient(colIri.toURI(), uid, pw);
    CloseableHttpResponse response = Common.sendChunk(dis, chunkSize, "POST", colIri.toURI(), "bag.zip.1",
            "application/octet-stream", http, chunkSize < zipFile.length());

    // 3. Check the response. If transfer corrupt (MD5 doesn't check out), report and exit.
    String bodyText = Common.readEntityAsString(response.getEntity());
    if (response.getStatusLine().getStatusCode() != 201) {
        System.err.println("FAILED. Status = " + response.getStatusLine());
        System.err.println("Response body follows:");
        System.err.println(bodyText);
        System.exit(2);// w  w w .ja  va2 s.c om
    }
    System.out.println("SUCCESS. Deposit receipt follows:");
    System.out.println(bodyText);

    Entry receipt = Common.parse(bodyText);
    Link seIriLink = receipt.getLink("edit");
    URI seIri = seIriLink.getHref().toURI();

    int remaining = (int) zipFile.length() - chunkSize;
    int count = 2;
    while (remaining > 0) {
        System.out.print(String.format("POST-ing chunk of %d bytes to SE-IRI (remaining: %d) ... ", chunkSize,
                remaining));
        response = Common.sendChunk(dis, chunkSize, "POST", seIri, "bag.zip." + count++,
                "application/octet-stream", http, remaining > chunkSize);
        remaining -= chunkSize;
        bodyText = Common.readEntityAsString(response.getEntity());
        if (response.getStatusLine().getStatusCode() != 200) {
            System.err.println("FAILED. Status = " + response.getStatusLine());
            System.err.println("Response body follows:");
            System.err.println(bodyText);
            System.exit(2);
        }
        System.out.println("SUCCESS.");
    }

    // 4. Get the statement URL. This is the URL from which to retrieve the current status of the deposit.
    System.out.println("Retrieving Statement IRI (Stat-IRI) from deposit receipt ...");
    receipt = Common.parse(bodyText);
    Link statIriLink = receipt.getLink("http://purl.org/net/sword/terms/statement");
    IRI statIri = statIriLink.getHref();
    System.out.println("Stat-IRI = " + statIri);

    // 5. Check statement every ten seconds (a bit too frantic, but okay for this test). If status changes:
    // report new status. If status is an error (INVALID, REJECTED, FAILED) or ARCHIVED: exit.
    return Common.trackDeposit(http, statIri.toURI());
}

From source file:com.guye.baffle.util.OS.java

public static void rmfile(String file) throws BaffleException {
    File del = new File(file);
    del.delete();
}

From source file:com.liferay.maven.plugins.util.FileUtil.java

public static boolean move(File source, File destination) {
    if (!source.exists()) {
        return false;
    }/*  w w  w .  j  av  a 2 s  .  com*/

    destination.delete();

    try {
        if (source.isDirectory()) {
            FileUtils.moveDirectory(source, destination);
        } else {
            FileUtils.moveFile(source, destination);
        }
    } catch (IOException ioe) {
        return false;
    }

    return true;
}

From source file:Main.java

public static int deleteFiles(Collection<File> files) {
    int n = 0;//from   w  w w . ja  v a  2s .  c o  m
    for (File file : files) {
        if (file.isDirectory()) {
            n += deleteFiles(Arrays.asList(file.listFiles()));
        }
        if (file.delete())
            n++;
    }
    return n;
}

From source file:com.amazonaws.services.dynamodbv2.online.index.integration.tests.TestUtils.java

public static void deleteFiles(String[] fileNames) {
    for (String fileName : fileNames) {
        File file = new File(fileName);
        if (file.exists()) {
            file.delete();
        }//w w w .  j  ava2 s .c om
    }
}

From source file:com.ms.commons.standalone.job.JobRunner.java

private static void clearStandaloneStopFile() {
    String standaloneStopPath = System.getProperty(Cons.STANDALONE_STOP_FILE);
    File standaloneStopFile = new File(standaloneStopPath);
    if (standaloneStopFile.exists()) {
        standaloneStopFile.delete();
    }//from   w  ww.j  a  va  2s  . c  o  m
}

From source file:Main.java

public static File rename(File file, String newName) {
    File newFile = new File(file.getParent(), newName);
    if (!newFile.equals(file)) {
        if (newFile.exists()) {
            if (newFile.delete()) {
            }/*from  www  .j a v a2s.c  o  m*/
        }
        if (file.renameTo(newFile)) {
        }
    }
    return newFile;
}

From source file:Main.java

private static void deleteFileAndAnyContents(File file) {
    if (file.isDirectory())
        for (File child : file.listFiles()) {
            deleteFileAndAnyContents(child);
        }/*from  w  w  w.  j  a v  a 2s  . c  om*/

    file.delete();
}

From source file:Main.java

public static boolean deleteFileByIntervalTime(File file, long intervalTime) {
    long time = System.currentTimeMillis();
    if (time - file.lastModified() > intervalTime) {
        file.delete();
    }/*from   w w w.  j a va 2s.c o m*/
    return true;
}