Here you can find the source of deleteDirectory(File file)
Parameter | Description |
---|---|
file | The file to be deleted |
Parameter | Description |
---|---|
IOException | Throws IOException if there isn't any directory |
public static void deleteDirectory(File file) throws IOException
//package com.java2s; import java.io.File; import java.io.IOException; public class Main { /**/*from www . java2 s . c om*/ * * Deletes the directory if the directory has no files. If the directory has files * it deletes all the files in the directory and then the directory gets delted * * @param file * The file to be deleted * @throws IOException * Throws IOException if there isn't any directory */ public static void deleteDirectory(File file) throws IOException { if (file.isDirectory()) { if (file.list().length == 0) { file.delete(); } else { String[] files = file.list(); for (String temp : files) { File fileDelete = new File(file, temp); deleteDirectory(fileDelete); } if (file.list().length == 0) { file.delete(); } } } else { file.delete(); } } }