Class FileUtils

java.lang.Object
org.carrot2.util.FileUtils

public class FileUtils extends Object
Various utility methods for working with Files.
  • Method Details

    • getCanonicalOrAbsoluteFile

      public static File getCanonicalOrAbsoluteFile(String path)
      Creates a new File from the provided path and attempts to execute File.getCanonicalFile(). In case of a failure, returns the result of File.getAbsoluteFile().
      Parameters:
      path - the path
      Returns:
      the canonical or absolute file
    • changeRoot

      public static String changeRoot(String file, String oldRoot, String newRoot)
      Changes the root directory of a file. For example, file is /a/b/c/d/e and oldRoot is /a/b/c, and newRoot is /x/y, the result will be /x/y/d/e.
      Parameters:
      file - the file
      oldRoot - the old root
      newRoot - the new root
      Returns:
      the string
    • canonicalize

      public static String canonicalize(String path, String separator)
      Removes useless segments in relative paths, e.g. replaces ../path/../other/file.css with ../other/file.css
      Parameters:
      path - the path
      separator - the separator
      Returns:
      the string
    • deleteThrowingExceptions

      public static void deleteThrowingExceptions(File... files) throws IOException
      Attempts to delete the provided files and throws an IOException in case File.delete() returns false for any of them.
      Parameters:
      files - the files
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • mkdirsThrowingExceptions

      public static void mkdirsThrowingExceptions(File dirs) throws IOException
      Calls File.mkdirs() on the provided argument and throws an IOException if the call returns false.
      Parameters:
      dirs - the dirs
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • isFileInParent

      public static boolean isFileInParent(File file, File parent)
      Returns true if file is contained in the parent directory or any parent of the parent directory.
      Parameters:
      file - the file
      parent - the parent
      Returns:
      true, if is file in parent