Here you can find the source of emptyDir(File dir)
public static void emptyDir(File dir)
//package com.java2s; /*-//from w w w .j a v a 2 s .co m * See the file LICENSE for redistribution information. * * Copyright (c) 2002, 2011 Oracle and/or its affiliates. All rights reserved. * */ import java.io.File; public class Main { public static void emptyDir(File dir) { if (dir.isDirectory()) { String[] files = dir.list(); if (files != null) { for (int i = 0; i < files.length; i += 1) { new File(dir, files[i]).delete(); } } } else { dir.delete(); dir.mkdirs(); } } }