Java File Path Delete deleteMultipleFiles(String filePath, int numberOfFiles)

Here you can find the source of deleteMultipleFiles(String filePath, int numberOfFiles)

Description

delete Multiple Files

License

Apache License

Declaration

public static void deleteMultipleFiles(String filePath, int numberOfFiles) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static void deleteMultipleFiles(String filePath, int numberOfFiles) {
        for (int i = 0; i < numberOfFiles; i++) {
            deleteRecursively(new File(filePath + "." + (i + 1)));
        }//from  w w  w. ja  va2 s.  c om
    }

    public static void deleteRecursively(File file) {
        if (!file.exists()) {
            return;
        }
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                deleteRecursively(child);
            }
        }
        if (!file.delete()) {
            throw new RuntimeException("Couldn't empty database.");
        }
    }
}

Related

  1. deleteIfExist(String filePath)
  2. deleteInPathTempFiles(String workingFolder)
  3. deleteInRemote(String host, String path)
  4. deleteJaasFile(String jaasPath)
  5. deleteKey(String path, String key)
  6. deleteNonEmptyDirectory(String dirPath)
  7. deleteOldStorageFile(String filepath)
  8. deleteParent(String filePath)
  9. deletePath(File dirPath)