Class FileUtil


  • public class FileUtil
    extends Object
    Helper methods for managing operations with the file system..
    Author:
    Rein Raudjärv
    • Constructor Detail

      • FileUtil

        public FileUtil()
    • Method Detail

      • copyFile

        public static void copyFile​(File srcFile,
                                    File destFile)
                             throws IOException
        Copies the given file to a new location.

        If the destination file already exists it will be overwritten.

        Parameters:
        srcFile - source file (not null, must exist).
        destFile - destination file (not null, parent directory must exist).
        Throws:
        IOException
      • copyAndClose

        public static void copyAndClose​(InputStream in,
                                        File outputFile)
                                 throws IOException
        Copies the given stream to a file.

        If the destination file already exists it will be overwritten.

        Parameters:
        in - source stream (not null).
        outputFile - destination file (not null, parent directory must exist).
        Throws:
        IOException
      • forceDelete

        public static void forceDelete​(File file)
                                throws IOException
        Deletes the given file or directory. Throws an IOException in case of any error.
        Throws:
        IOException
      • getExtension

        public static String getExtension​(File file)
        Returns the extension of a given file or null if the file has no extension.
        Parameters:
        file - input file (not null).
      • canWriteToDir

        public static boolean canWriteToDir​(File dir)
      • getBytes

        public static byte[] getBytes​(File f)
      • getUniqueParentDirs

        public static Collection<File> getUniqueParentDirs​(Collection<File> files)
        Parameters:
        files - Collection of files
        Returns:
        files containing only parent directories. For example if there are [C:\weblogic\x\y, C:\weblogic\, C:\tomcat], then result is [C:\weblogic\, C:\tomcat], because C:\weblogic\x\y is a subdirectory of C:\weblogic