Class FileUtils

java.lang.Object
io.github.amanzat.util.FileUtils

public final class FileUtils extends Object
Miscellaneous file related utilities.
  • Field Details

    • UNIX_SEPARATOR

      public static final char UNIX_SEPARATOR
      The Unix path separator.
      See Also:
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • readAllLines

      public static List<String> readAllLines(String filePath) throws IOException
      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

      public static boolean ensureDirectoryExists(String path)
      Ensures that the directory at the specified path exists.
      Parameters:
      path - The directory path
      Returns:
      true if the directory exists, false otherwise.
    • deleteFile

      public static boolean deleteFile(String filePath)
      Deletes the file at the specified path if exists.
      Parameters:
      filePath - The file path
      Returns:
      true if the file was deleted, false otherwise.
    • getFileName

      public static String getFileName(String path)
      Returns the file name from the specified path by eliminating the directories or null if the path is null.
      Parameters:
      path - The path
      Returns:
      The file name from the specified path by eliminating the directories or null if the path is null.
    • indexOfLastDirectorySeparator

      public static int indexOfLastDirectorySeparator(String path)
      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.