Class FileHelper


  • public final class FileHelper
    extends Object
    Utility class for creating and deleting directories for files.
    • Method Detail

      • createDirectoriesForFile

        public static void createDirectoriesForFile​(String fileName)
                                             throws IOException
        For given path creates all parent directories of a path. E.g. /tmp/sub/somefile.txt will create the directories: /tmp/sub
        Parameters:
        fileName - File name (path)
        Throws:
        IOException - If creating directories fails
      • createDirectoriesForFile

        public static void createDirectoriesForFile​(File file)
                                             throws IOException
        For given file creates all parent directories of it. E.g. /tmp/sub/somefile.txt will create the directories: /tmp/sub
        Parameters:
        file - File name (path)
        Throws:
        IOException - If creating directories fails
      • createDirectories

        public static void createDirectories​(File directory)
                                      throws IOException
        For given directory creates all directories. The file must point to a directory. E.g. /tmp/sub/another will create the directories: /tmp/sub;/another
        Parameters:
        directory - File directory (path)
        Throws:
        IOException - If creating directories fails or of directory does not specify a directory path
      • deleteRecursive

        public static void deleteRecursive​(File file)
                                    throws IOException
        Recursively deletes all files/sub-directories of given file, including the file (or directory) itself. There is one restriction: It does not delete paths with a length < than 8, an IOException is thrown then.
        Parameters:
        file - File or directory to (recursively) delete
        Throws:
        IOException - If deletion fails or given file has path length of less than 8