Class FileUtils


  • public final class FileUtils
    extends Object
    File Utilities
    Author:
    Brian Wyka
    • Method Detail

      • deriveRelativePath

        public static String deriveRelativePath​(String root,
                                                String absolutePath)
        Derive the relative path for absolutePath relative to root
        Parameters:
        root - the root to determine relativity
        absolutePath - the absolute path
        Returns:
        the path relative to the root
      • find

        public static Stream<Path> find​(String root,
                                        String pathOrPattern)
                                 throws IOException
        Find file paths by a glob pattern.

        If a glob pattern is not provided, then this method will return a stream of one Path representation for the provided arguments (if the path exists), otherwise an empty stream.

        In other words, this method will only ever return a stream of actual files which exist.

        Parameters:
        root - the start location to search
        pathOrPattern - the path or glob pattern, i.e **/path/**/*.txt
        Returns:
        the collection of paths which match the pattern, or an empty collection if no matches found
        Throws:
        IOException - if any error occurs walking the file tree attempting to match paths
      • isGlobPattern

        public static boolean isGlobPattern​(String pattern)
        Determine if the provided pattern is a glob pattern
        Parameters:
        pattern - the pattern to check
        Returns:
        true if a glob pattern, false otherwise