Here you can find the source of delete(File file)
public static void delete(File file)
//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())); } }