Here you can find the source of deleteFile(final File f, final int attempts, final long sleepTime)
public static boolean deleteFile(final File f, final int attempts, final long sleepTime)
//package com.java2s; /**/* ww w.j a v a 2s.c om*/ * Copyright (C) 2015 BonitaSoft S.A. * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation * version 2.1 of the License. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301, USA. **/ import java.io.File; public class Main { public static boolean deleteFile(final File f, final int attempts, final long sleepTime) { int retries = attempts; while (retries > 0) { if (f.delete()) { break; } retries--; try { Thread.sleep(sleepTime); } catch (final InterruptedException e) { } } return retries > 0; } }