java删除文件夹下所有文件

package org.sw;

import java.io.File;

/**
 * 
 * @author mengzw
 * @since 3.0 2014-2-26
 */
public class DeleteFolder {
    
    /**
     * 删除文件夹下的所有文件
     * @param oldPath
     */
    public void deleteFile(File oldPath) {
          if (oldPath.isDirectory()) {
           System.out.println(oldPath + "是文件夹--");
           File[] files = oldPath.listFiles();
           for (File file : files) {
             deleteFile(file);
           }
          }else{
            oldPath.delete();
          }
        }
    
    public static void main(String[] args) {
        DeleteFolder df =  new DeleteFolder();
        df.deleteFile(new File("E:/ddd/"));
    }
}

 

posted @ 2014-02-26 18:36  IT Daren  阅读(1002)  评论(1编辑  收藏  举报