Here you can find the source of delAllFiles(File dir, String prefix)
Parameter | Description |
---|---|
dir | a parameter |
prefix | a parameter |
public static boolean delAllFiles(File dir, String prefix)
//package com.java2s; /*//from w w w. jav a 2s. c o m * Copyright (c) Fiorano Software Pte. Ltd. and affiliates. All rights reserved. http://www.fiorano.com * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ import java.io.*; public class Main { /** * @param dir * @param prefix * @return */ public static boolean delAllFiles(File dir, String prefix) { boolean bUnableToDeleteSomeFiles = false; String[] fileList = dir.list(); String path = dir.getAbsolutePath() + File.separator; File file; for (int i = 0; i < fileList.length; ++i) { if (fileList[i].startsWith(prefix)) { try { file = new File(path + fileList[i]); file.delete(); } catch (Exception e) { // No problem continue with the cleanup of // rest of the files. // bUnableToDeleteSomeFiles = true; } } } return bUnableToDeleteSomeFiles; } }