Home > Java > javaTutorial > Java delete all files in a folder example sharing

Java delete all files in a folder example sharing

高洛峰
Release: 2017-01-11 14:59:47
Original
1620 people have browsed it

package org.sw;
import java.io.File;
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/"));
    }
}
Copy after login

For more java deletion of all files in a folder examples and related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template