/*
* Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
public class IOHelper {
+ /**
+ * Deletes files and directories recursively. WARNING!!! Follows symlinks!!!
+ */
+ public static void deleteRecursively(final File file) throws IOException {
+ if (file.isDirectory()) {
+
+ for (final File subFile : file.listFiles())
+ deleteRecursively(subFile);
+
+ if (!file.delete())
+ throw new FileNotFoundException("Failed to delete directory: "
+ + file);
+
+ return;
+ }
+
+ if (file.isFile())
+ if (!file.delete())
+ throw new FileNotFoundException("Failed to delete file: "
+ + file);
+ }
+
public static byte[] getFileContents(final File file)
throws FileNotFoundException, IOException {