代码如下:

import java.io.File;

public class deleteFileDemo {
    public static void main(String []args) {
    	//指定目录
    	File folder=new File("E:/java/workplace/test/测试");
    	deleteFolder(folder);
    }
    public static void deleteFolder(File folder) {
    	File [] files=folder.listFiles();
    	if(files !=null) {
    		for (File f:files) {
    			if (f.isDirectory()) {   			
    				deleteFolder(f);
    			}  			
    		}		
    	}
    	//如果为空文件夹
        if(files.length<1) {
        	folder.delete();
        }
    }
}