Class FileUtils

java.lang.Object
is.galia.util.FileUtils

public final class FileUtils extends Object
  • Method Details

    • checkReadableFile

      public static boolean checkReadableFile(Path path) throws IOException
      Parameters:
      path - Path of the file to check.
      Returns:
      Whether the file at the given path exists, is a file, and is readable.
      Throws:
      AccessDeniedException - if the file is not readable. The message is user-friendly.
      NoSuchFileException - if the file does not exist. The message is user-friendly.
      IOException - if the file does not exist, is not a file, or is not readable. The message is user-friendly.
    • checkWritableDirectory

      public static boolean checkWritableDirectory(Path path) throws IOException
      Parameters:
      path - Path of the directory to check.
      Returns:
      Whether the directory at the given path exists, is a file, and is writable.
      Throws:
      AccessDeniedException - if the directory is not writable. The message is user-friendly.
      NoSuchFileException - if the directory does not exist. The message is user-friendly.
      IOException - if the file is not a directory. The message is user-friendly.
    • expandPath

      public static String expandPath(String path)
      Expands filesystem paths that start with a tilde (~).
      Parameters:
      path - Path to expand.
      Returns:
      Expanded path.
    • locate

      public static Path locate(String file)

      Tries to resolve the location of the file with the given pathname. Existence of the underlying file is not checked.

      1. If the pathname is absolute, it is returned as-is.
      2. If the pathname starts with a tilde (~, an expanded path is returned.
      3. If it is a filename or relative pathname, it is located (relative pathname intact) in the current working directory.
      Parameters:
      file - Absolute or relative pathname or filename.
      Returns:
      Absolute path.