Class FileUtilities


  • public class FileUtilities
    extends Object
    Utilities for file(s) and directory
    Author:
    Erwan Bocher, CNRS, 2020
    • Constructor Detail

      • FileUtilities

        public FileUtilities()
    • Method Detail

      • deleteFiles

        public static boolean deleteFiles​(File directory)
                                   throws IOException
        Use this method to delete all files in directory recursively without deleting the root directory
        Parameters:
        directory - the directory
        Returns:
        true if the directory already exists
        Throws:
        IOException
      • deleteFiles

        public static boolean deleteFiles​(File directory,
                                          boolean delete)
                                   throws IOException
        Use this method to delete all files in directory recursively. The root directory can be deleted
        Parameters:
        directory - the directory
        delete - true to delete the root directory
        Returns:
        true if the directory already exists
        Throws:
        IOException
      • listFiles

        public static List<String> listFiles​(File directory,
                                             String extension)
                                      throws IOException
        List all files
        Parameters:
        directory - the directory
        extension - file extension, txt, geojson, shapefile
        Returns:
        path of the files
        Throws:
        IOException
      • listFiles

        public static List<String> listFiles​(File directory)
                                      throws IOException
        List all files in a directory
        Parameters:
        directory - the directory
        Returns:
        path of the files
        Throws:
        IOException
      • zip

        public static void zip​(File[] filesToZip,
                               File outFile)
                        throws IOException
        Zips the specified files
        Parameters:
        filesToZip -
        outFile -
        Throws:
        IOException
      • zip

        public static void zip​(File toZip,
                               File outFile)
                        throws IOException
        Zips the specified file or folder
        Parameters:
        toZip -
        outFile -
        Throws:
        IOException
      • getRelativePath

        public static String getRelativePath​(File base,
                                             File file)
        Get the relative path to file, according to the path to base
        Parameters:
        base -
        file -
        Returns:
      • isExtensionWellFormated

        public static boolean isExtensionWellFormated​(File file,
                                                      String prefix)
        Check if the file has the good extension
        Parameters:
        file -
        prefix -
        Returns: