Here you can find the source of delete(File file)
Parameter | Description |
---|---|
file | the file to delete |
public static boolean delete(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**//w w w. ja v a2s . co m * Recursively deletes the given {@link File} {@code file}. If the {@code file} is a directory, this method deletes * all sub-files of that directory by calling itself on the sub-file. Otherwise, it simply deletes the file using * {@link File#delete()}. * * @param file * the file to delete * * @return {@code true} iff the file was successfully deleted, {@code false} otherwise */ public static boolean delete(File file) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File f : files) { delete(f); } } } return file.delete(); } /** * Recursively deletes the given {@link File} {@code file}. If the {@code file} is a directory, this method deletes * all sub-files of that directory by calling itself on the sub-file. Otherwise, it simply deletes the file using * {@link File#delete()}. The given {@code maxDepth} is used to limit the recursive process to a maximum directory * depth. If it set to {@code 0}, it is ignored whether or not the given {@code file} is a directory. * * @param file * the file to delete * @param maxDepth * the maximum recursion depth * * @return {@code true} iff the file was successfully deleted, {@code false} otherwise */ public static boolean delete(File file, int maxDepth) { if (maxDepth > 0 && file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File f : files) { delete(f, maxDepth - 1); } } } return file.delete(); } }