Here you can find the source of recursiveDelete(File f)
Parameter | Description |
---|---|
f | The file handler |
Parameter | Description |
---|---|
IOException | Thrown if a file could not be deleted |
public static void recursiveDelete(File f) throws IOException
//package com.java2s; /*/* w w w.ja v a 2s . c o m*/ * IronJacamar, a Java EE Connector Architecture implementation * Copyright 2016, Red Hat Inc, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the Eclipse Public License 1.0 as * published by the Free Software Foundation. * * This software 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 Eclipse * Public License for more details. * * You should have received a copy of the Eclipse Public License * along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ import java.io.File; import java.io.IOException; public class Main { /** * Recursive delete * * @param f The file handler * @throws IOException Thrown if a file could not be deleted */ public static void recursiveDelete(File f) throws IOException { if (f != null && f.exists()) { File[] files = f.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { recursiveDelete(files[i]); } else { if (!files[i].delete()) throw new IOException("Could not delete " + files[i]); } } } if (!f.delete()) throw new IOException("Could not delete " + f); } } }