Here you can find the source of deleteIfExists(final File file)
private static boolean deleteIfExists(final File file)
//package com.java2s; /****************************************************************************** * Copyright (c) 2000-2017 Ericsson Telecom AB * 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 { private static boolean deleteIfExists(final File file) { return file.exists() && !file.delete(); }// w w w. j a v a2s .co m /** * Deletes a file. * @param file the file to delete * @throws IOException if the file cannot be deleted */ public static void delete(final File file) throws IOException { if (deleteIfExists(file)) { throw new IOException("The file cannot be deleted: " + file.getAbsolutePath()); } } }