Class FileUtils


  • public final class FileUtils
    extends Object
    File utilities.
    • Method Detail

      • fileFromUri

        public static File fileFromUri​(URI uri)
        Tries to convert the specified URI to a file object. If this fails, null is returned.
        Parameters:
        uri - the URI
        Returns:
        the resulting file object
      • isFile

        public static boolean isFile​(URL url)
      • getFileExtension

        public static String getFileExtension​(File file)
      • mkdir

        public static void mkdir​(File dir,
                                 boolean createDirectoryIfNotExisting)
                          throws IOException
        Asserts that the given directory exists and creates it if necessary.
        Parameters:
        dir - the directory that shall exist
        createDirectoryIfNotExisting - specifies if the directory shall be created if it does not exist.
        Throws:
        IOException - thrown if the directory could not be created.
      • makeParentDirs

        public static void makeParentDirs​(File file)
                                   throws IOException
        Creates the parent directories for the given File.
        Parameters:
        file -
        Throws:
        IOException
      • defineFilePosixAttributeView

        public static void defineFilePosixAttributeView​(Path path,
                                                        Set<PosixFilePermission> filePermissions,
                                                        String fileOwner,
                                                        String fileGroup)
                                                 throws IOException
        Define file posix attribute view on a path/file.
        Parameters:
        path - Target path
        filePermissions - Permissions to apply
        fileOwner - File owner
        fileGroup - File group
        Throws:
        IOException - If IO error during definition of file attribute view
      • isFilePosixAttributeViewSupported

        public static boolean isFilePosixAttributeViewSupported()
        Check if posix file attribute view is supported on the default FileSystem.
        Returns:
        true if posix file attribute view supported, false otherwise