Class FileUtilities
public final class FileUtilities
Static utility methods for working with file system paths and URIs, including recursive file lookup, extension/name parsing, parent directory
resolution and human-readable byte size formatting.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringThis method combines the specified basepath with the parts provided as arguments.Recursively collects all files underdirwhose absolute path ends with one of the suppliedfilesnames.findFilesByExtension(List<String> fileNames, Path dir, String extension) Recursively collects all files underdirwhose absolute path ends with the suppliedextension.static StringgetExtension(String path) Returns the extension of the supplied path string (without the leading dot), or an empty string if the path has no extension.static StringgetExtension(Path file) Returns the extension of the supplied file path (without the leading dot), or an empty string if the path has no extension.static StringgetFileName(String path) Returns the file name (without extension) of the supplied path string.static StringgetFileName(String path, boolean extension) Returns the file name of the supplied path string, optionally including the extension.static StringgetFileName(URL path) Returns the file name (without extension) of the supplied URL.static StringgetParentDirPath(String uri) static StringgetParentDirPath(URI uri) static StringhumanReadableByteCount(long bytes) static StringhumanReadableByteCount(long bytes, boolean decimal)
-
Method Details
-
findFilesByExtension
Recursively collects all files underdirwhose absolute path ends with the suppliedextension.- Parameters:
fileNames- the (mutable) list that receives the matching file pathsdir- the directory to searchextension- the file extension to look for- Returns:
fileNamesfor chaining
-
findFiles
Recursively collects all files underdirwhose absolute path ends with one of the suppliedfilesnames.- Parameters:
fileNames- the (mutable) list that receives the matching file pathsdir- the directory to searchfiles- the file name suffixes to look for- Returns:
fileNamesfor chaining
-
getExtension
-
getExtension
-
getFileName
-
getFileName
-
getFileName
-
getParentDirPath
-
getParentDirPath
-
combine
This method combines the specified basepath with the parts provided as arguments. The output will use the path separator of the current system;- Parameters:
basePath- The base path for the combined path.paths- The parts of the path to be constructed.- Returns:
- The combined path.
-
humanReadableByteCount
-
humanReadableByteCount
-