Package org.carrot2.util
Class FileUtils
java.lang.Object
org.carrot2.util.FileUtils
Various utility methods for working with
Files.-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcanonicalize(String path, String separator) Removes useless segments in relative paths, e.g.static StringchangeRoot(String file, String oldRoot, String newRoot) Changes the root directory of a file.static voiddeleteThrowingExceptions(File... files) Attempts to delete the provided files and throws anIOExceptionin caseFile.delete()returnsfalsefor any of them.static FileCreates a newFilefrom the provided path and attempts to executeFile.getCanonicalFile().static booleanisFileInParent(File file, File parent) Returnstrueif file is contained in the parent directory or any parent of the parent directory.static voidmkdirsThrowingExceptions(File dirs)
-
Method Details
-
getCanonicalOrAbsoluteFile
Creates a newFilefrom the provided path and attempts to executeFile.getCanonicalFile(). In case of a failure, returns the result ofFile.getAbsoluteFile().- Parameters:
path- the path- Returns:
- the canonical or absolute file
-
changeRoot
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 fileoldRoot- the old rootnewRoot- the new root- Returns:
- the string
-
canonicalize
Removes useless segments in relative paths, e.g. replaces../path/../other/file.csswith../other/file.css- Parameters:
path- the pathseparator- the separator- Returns:
- the string
-
deleteThrowingExceptions
Attempts to delete the provided files and throws anIOExceptionin caseFile.delete()returnsfalsefor any of them.- Parameters:
files- the files- Throws:
IOException- Signals that an I/O exception has occurred.
-
mkdirsThrowingExceptions
- Parameters:
dirs- the dirs- Throws:
IOException- Signals that an I/O exception has occurred.
-
isFileInParent
Returnstrueif file is contained in the parent directory or any parent of the parent directory.- Parameters:
file- the fileparent- the parent- Returns:
- true, if is file in parent
-