From cf059bc72e1a7cc4486409fca6c721c0f2e83711 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Tue, 2 Sep 2008 14:32:25 +0000 Subject: QPID-1268 : Added single delete and recursive delete method to common FileUtils. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@691264 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/qpid/util/FileUtils.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'java/common/src') diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 7494745457..814d6e73c9 100644 --- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -192,4 +192,35 @@ public class FileUtils throw new RuntimeException(e); } } + + /* + * Deletes a given file + */ + public static void deleteFile(String filePath) throws IOException + { + delete(new File(filePath), false); + } + + /** + * Delete a given file, if a directory is specified and recursive set then delete the whole tree + * @param filePath the File object to start at + * @param recursive boolean to recurse if a directory is specified. + * @throws IOException + */ + public static void delete(File filePath, boolean recursive) throws IOException + { + if (filePath.isDirectory()) + { + if (recursive) + { + for (File subFile : filePath.listFiles()) + { + delete(subFile, true); + } + } + } + + filePath.delete(); + } + } -- cgit v1.2.1