Here you can find the source of delTree(File file)
Parameter | Description |
---|---|
file | to delete |
public static boolean delTree(File file)
//package com.java2s; /*//from ww w . j a v a 2s . c o m * Gruntspud * * Copyright (C) 2002 Brett Smith. * * Written by: Brett Smith <t_magicthize@users.sourceforge.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * This program 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 Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import java.io.File; public class Main { /** * Delete a directory recursively or delete a single file * * @param file to delete * @return true if sucessfully deleted */ public static boolean delTree(File file) { if (file.exists()) { if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; files != null && i < files.length; i++) { if (!delTree(files[i])) { return false; } } } if (!file.delete()) { return false; } else { if (file.exists()) { return false; } } return true; } else { return false; } } }