Here you can find the source of deleteFile(final String dirname)
Parameter | Description |
---|---|
dirname | a parameter |
public static boolean deleteFile(final String dirname)
//package com.java2s; /*-------------------------------------------------------- * Copyright (c) 2011, The Dojo Foundation * This software is distributed under the "Simplified BSD license", * the text of which is available at http://www.winktoolkit.org/licence.txt * or see the "license.txt" file for more details. *--------------------------------------------------------*/ import java.io.File; public class Main { /**//from w w w . j a va 2 s . c o m * @param dirname * @return */ public static boolean deleteFile(final String dirname) { // System.out.println("deleteFile: " + dirname); final File f = new File(dirname); if (f.exists()) { return deleteR(f); } return false; } /** * @param path * @return */ private static boolean deleteR(final File path) { if (path.exists()) { final File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteR(files[i]); } else { final boolean isFileDeleted = files[i].delete(); if (!isFileDeleted) { return false; } } } } final boolean isDeleted = path.delete(); return isDeleted; } /** * @param dirname * @return */ public static boolean isDirectory(final String dirname) { // System.out.println("isDirectory: " + dirname); final File f = new File(dirname); if (f.exists() && f.isDirectory() && f.canWrite()) { return true; } return false; } }