Here you can find the source of deleteFolder(File folder)
Parameter | Description |
---|---|
folder | The root of the folder hierarchy to be deleted. |
public static void deleteFolder(File folder)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { /**/*from ww w .j a v a2s . c o m*/ * This method recursively deletes a folder. This is intended to delete * temporary folders used in tests. This method prints a message to stdout * if it is not able to delete the given folder. Typically this indicates * that a file in the hierarchy is still locked, probably because a stream * on it was not closed. * * @param folder * The root of the folder hierarchy to be deleted. */ public static void deleteFolder(File folder) { File[] files = folder.listFiles(); for (File file : files) { if (file.isDirectory()) { deleteFolder(file); } file.delete(); } if (!folder.delete()) { System.out.println("Folder not deleted: " + folder.getPath()); } } }