Java File Delete delete(File file)

Here you can find the source of delete(File file)

Description

delete

License

Open Source License

Declaration

public static void delete(File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 - 2017 Certiv Analytics and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

import java.io.File;

import java.io.IOException;

public class Main {
    public static void delete(File file) {
        if (!file.exists())
            return;
        if (file.delete())
            return;
        System.gc();/*from  w  w w.j a va 2  s  .  c o m*/
        if (file.delete())
            return;

        try {
            Thread.sleep(50L);
        } catch (InterruptedException interruptedexception) {
        }
        file.delete();
        if (!file.exists())
            return;

        // if (file.isDirectory() && isSymLink(file)
        // && (Utils.getOperatingSystem().contains("linux") ||
        // Utils.getOperatingSystem().contains("unix"))) {
        // String path = file.getAbsolutePath();
        // DotGen p = new DotGen((new StringBuilder("rm -f ")).append(path).toString());
        // p.run();
        // p.waitFor(1000L);
        // if (!file.exists()) {
        // return;
        // } else {
        // throw new RuntimeException(new IOException((new StringBuilder("Could not delete
        // file")).append(file)
        // .append("; ").append(p.getError()).toString()));
        // }
        // } else {
        // throw new RuntimeException(
        // new IOException((new StringBuilder("Could not delete file ")).append(file).toString()));
        // }

        throw new RuntimeException(
                new IOException((new StringBuilder("Could not delete file ")).append(file).toString()));
    }
}

Related

  1. delete(File file)
  2. delete(File file)
  3. delete(File file)
  4. delete(File file)
  5. delete(File file)
  6. doDelete(File f)
  7. doDelete(File file)
  8. doDelete(File file)
  9. doDelete(File path)