Package io.github.amanzat.util
Class FileUtils
java.lang.Object
io.github.amanzat.util.FileUtils
Miscellaneous file related utilities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleandeleteFile(String filePath) Deletes the file at the specified path if exists.static booleanensureDirectoryExists(String path) Ensures that the directory at the specified path exists.static StringgetFileName(String path) Returns the file name from the specified path by eliminating the directories ornullif the path isnull.static intReturns the index of the last directory separator character of the path or -1 if there is no such character.readAllLines(String filePath) Reads all lines from the file at the given file path.
-
Field Details
-
UNIX_SEPARATOR
public static final char UNIX_SEPARATORThe Unix path separator.- See Also:
-
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
readAllLines
Reads all lines from the file at the given file path.- Parameters:
filePath- The file path- Returns:
- A list with the file lines.
- Throws:
IOException- if an I/O error occurs
-
ensureDirectoryExists
Ensures that the directory at the specified path exists.- Parameters:
path- The directory path- Returns:
trueif the directory exists,falseotherwise.
-
deleteFile
Deletes the file at the specified path if exists.- Parameters:
filePath- The file path- Returns:
trueif the file was deleted,falseotherwise.
-
getFileName
Returns the file name from the specified path by eliminating the directories ornullif the path isnull.- Parameters:
path- The path- Returns:
- The file name from the specified path by eliminating the directories or
nullif the path isnull.
-
indexOfLastDirectorySeparator
Returns the index of the last directory separator character of the path or -1 if there is no such character.- Parameters:
path- The path- Returns:
- The index of the last directory separator character of the path or -1 if there is no such character.
-