Here you can find the source of recursiveDelete(File file)
Parameter | Description |
---|---|
file | File or directory to delete |
public static void recursiveDelete(File file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 MadRobot.// w w w . j a v a2s. com * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Elton Kent - initial API and implementation ******************************************************************************/ import java.io.File; public class Main { /** * Recursively delete the contents of a directory or just delete a file * * @param file * File or directory to delete */ public static void recursiveDelete(File file) { if (!file.exists()) return; if (file.isDirectory()) { File[] contents = file.listFiles(); for (int i = 0; i < contents.length; i++) recursiveDelete(contents[i]); } try { file.delete(); } catch (Exception e) { e.printStackTrace(); } } }