Here you can find the source of clearFileOrDir(File file)
Parameter | Description |
---|---|
file | to be cleared |
public static void clearFileOrDir(File file)
//package com.java2s; import java.io.File; public class Main { /**/*www . j a v a 2 s . co m*/ * Clear directory * * @param file to be cleared */ public static void clearFileOrDir(File file) { if (!file.exists()) { return; } if (file.isFile()) { file.delete(); return; } File[] children = file.listFiles(); if (children == null || children.length == 0) { file.delete(); return; } for (File child : children) { clearFileOrDir(child); } file.delete(); } /** * Clear directory * * @param dir to be cleared */ public static void clearFileOrDir(String dir) { File file = new File(dir); clearFileOrDir(file); } }