Here you can find the source of deleteFile(String filename)
Parameter | Description |
---|---|
file | file to delete |
Parameter | Description |
---|---|
Exception | if the file couldn't be deleted for any reason |
public static void deleteFile(String filename) throws Exception
//package com.java2s; /*-/*from ww w. j av a2 s . c o m*/ ******************************************************************************* * Copyright (c) 2011, 2016 Diamond Light Source Ltd. * 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 * * Contributors: * Matthew Gerring - initial API and implementation and/or initial documentation *******************************************************************************/ import java.io.File; public class Main { /** * Utility method to delete a file if it exists. * @param file file to delete * @throws Exception if the file couldn't be deleted for any reason */ public static void deleteFile(String filename) throws Exception { File file = new File(filename); if (file.exists()) { if (!file.delete()) { throw new Exception("Could not delete file " + file); } } } }