Here you can find the source of deleteFile(File path)
Parameter | Description |
---|---|
path | File or Directory to be deleted |
public static boolean deleteFile(File path)
//package com.java2s; /*// w ww . j a v a 2s . co m * #%L * Osm2garminAPI * %% * Copyright (C) 2011 - 2012 Frantisek Mantlik <frantisek at mantlik.cz> * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-2.0.html>. * #L% */ import java.io.*; public class Main { /** * This function will recursively delete directories and files. * * @param path File or Directory to be deleted * @return true indicates success. */ public static boolean deleteFile(File path) { if (path.exists()) { if (path.isDirectory()) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { if (!deleteFile(files[i])) { try { Thread.sleep(300); } catch (InterruptedException ex) { } deleteFile(files[i]); } } else { if (!files[i].delete()) { try { Thread.sleep(300); } catch (InterruptedException ex) { } files[i].delete(); } } } } } if (!path.delete()) { try { Thread.sleep(300); } catch (InterruptedException ex) { } return path.delete(); } else { return true; } } }