Java Delete Directory deleteFiles(File dir)

Here you can find the source of deleteFiles(File dir)

Description

delete Files

License

Open Source License

Declaration

private static void deleteFiles(File dir) 

Method Source Code


//package com.java2s;
/*/*  w ww  . java  2 s.c o  m*/
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import java.io.File;

public class Main {
    private static void deleteFiles(File dir) {
        File[] files = dir.listFiles();
        if (files == null)
            return; // I/O error

        // delete files in the directory
        for (int i = 0; i < files.length; i++) {
            File file = files[i];

            // delete any child files
            if (file.isDirectory())
                deleteFiles(file);

            file.delete();
        }
    }
}

Related

  1. deleteDirectoryContents(File directory)
  2. deleteDirectoryContents(File directory)
  3. deleteDirectoryContents(final File dir)
  4. deleteDirectoryContents(final File dir, int deleteDirLevel, int level)
  5. deleteFiles(File dir)
  6. deleteFiles(File directory)
  7. deleteFiles(File directory)
  8. deleteFiles(File directory)
  9. deleteFiles(File directory, String prefix)