Here you can find the source of deleteAndCreateFolder(String path)
public static String deleteAndCreateFolder(String path) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { public static String deleteAndCreateFolder(String path) throws IOException { boolean success_del; File folder = new File(path); success_del = deleteDirectory(folder); if (!success_del) { // Deletion failed throw new IOException(); }/*from w w w .ja va2 s .c o m*/ File newFolder = new File(path); if (newFolder.mkdir() == true) { return path; } else { throw new IOException(); } } static boolean deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return (path.delete()); } }