Here you can find the source of deleteDirectory(String directoryName)
Parameter | Description |
---|---|
directoryName | the string representing the directory to be deleted. |
public static void deleteDirectory(String directoryName)
//package com.java2s; //License from project: LGPL import java.io.File; public class Main { /**/* www . j av a2 s .co m*/ * Deletes the directory (and any files) represented by <tt>directoryName</tt>, if directory * doesn't exits does nothing. * @param directoryName the string representing the directory to be deleted. */ public static void deleteDirectory(String directoryName) { File directory = new File(directoryName); if (directory.exists()) { if (directory.isDirectory()) { File[] files = directory.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) deleteDirectory(file.getAbsolutePath()); file.delete(); } } } directory.delete(); } } /** * Given a string representing a file determines whether the file exists. * @param filename the string representing the path of the file. * @return tru if the file exists, false otherwise. */ public static boolean exists(String filename) { File f = new File(filename); return f.exists(); } }