Here you can find the source of deleteFileOrDir(File filehandle)
Parameter | Description |
---|---|
filehandle | a parameter |
public static boolean deleteFileOrDir(File filehandle)
//package com.java2s; /*/*from w w w . j a v a 2 s .c o m*/ * Stage - Spatial Toolbox And Geoscript Environment * (C) HydroloGIS - www.hydrologis.com * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html). */ import java.io.File; public class Main { /** * Returns true if all deletions were successful. If a deletion fails, the method stops * attempting to delete and returns false. * * @param filehandle * @return true if all deletions were successful */ public static boolean deleteFileOrDir(File filehandle) { if (filehandle.isDirectory()) { String[] children = filehandle.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteFileOrDir(new File(filehandle, children[i])); if (!success) { return false; } } } // The directory is now empty so delete it boolean isdel = filehandle.delete(); if (!isdel) { // if it didn't work, which often happens on windows systems, // remove on exit filehandle.deleteOnExit(); } return isdel; } }