Here you can find the source of deleteDirectory(File directory)
Parameter | Description |
---|---|
directory | the directory |
public static boolean deleteDirectory(File directory)
//package com.java2s; /* SpagoBI, the Open Source Business Intelligence suite /*www.ja va2s . c o m*/ * Copyright (C) 2012 Engineering Ingegneria Informatica S.p.A. - SpagoBI Competency Center * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0, without the "Incompatible With Secondary Licenses" notice. * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.io.File; public class Main { /** * Delete directory. * * @param directory the directory * * @return true, if successful */ public static boolean deleteDirectory(File directory) { try { if (directory.isDirectory()) { File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isFile()) { boolean deletion = file.delete(); if (!deletion) return false; } else deleteDirectory(file); } } boolean deletion = directory.delete(); if (!deletion) return false; } catch (Exception e) { return false; } return true; } }