Class FileUtil

java.lang.Object
com.github.toolarium.common.util.FileUtil

public final class FileUtil extends Object
Defines a file utility.
  • Field Details

  • Method Details

    • getInstance

      public static FileUtil getInstance()
      Get the instance
      Returns:
      the instance
    • simplifyPath

      public String simplifyPath(String path)
      Simplify a given path
      Parameters:
      path - the path to simplify
      Returns:
      the path
    • slashify

      public String slashify(String path)
      Slashify the path
      Parameters:
      path - the path
      Returns:
      the prepared path
    • existFile

      public boolean existFile(String fileName)
      Check if a given file exist
      Parameters:
      fileName - the filename
      Returns:
      true if the file exist otherwise false
    • isReadable

      public boolean isReadable(String fileName)
      Checks whether the given file or directory is readable.
      Parameters:
      fileName - the filename to be checked
      Returns:
      true if the file can be read otherwise false
    • isWritable

      public boolean isWritable(String fileName)
      Checks whether the given file or directory is writable.
      Parameters:
      fileName - the filename to be checked
      Returns:
      true if the file can be written otherwise false
    • removeFile

      public boolean removeFile(String fileName)
      Removes a file
      Parameters:
      fileName - the file to remove
      Returns:
      returns true if all deletions were successful.
    • removeFile

      public boolean removeFile(File file)
      Removes a file
      Parameters:
      file - the file to remove
      Returns:
      removes a file
    • removeDirectory

      public boolean removeDirectory(Path dir)
      Deletes all files and sub directories under dir. If a deletion fails, the method stops attempting to delete and returns false.
      Parameters:
      dir - the directory to delete
      Returns:
      returns true if all deletions were successful.
    • removeDirectory

      public boolean removeDirectory(File dir)
      Deletes all files and sub directories under dir. If a deletion fails, the method stops attempting to delete and returns false.
      Parameters:
      dir - the directory to delete
      Returns:
      returns true if all deletions were successful.
    • extractURLPath

      public String extractURLPath(URL url)
      Extract the path from an url
      Parameters:
      url - the url
      Returns:
      the path
    • readFileContent

      public String readFileContent(File file) throws IOException
      Read the file content
      Parameters:
      file - the file
      Returns:
      the content
      Throws:
      IOException - In case of an IO error
    • readFileContent

      public String readFileContent(Path file) throws IOException
      Read the file content
      Parameters:
      file - the file
      Returns:
      the content
      Throws:
      IOException - In case of an IO error
    • readFileContent

      public String readFileContent(File file, Charset charset) throws IOException
      Read the file content
      Parameters:
      file - the file
      charset - the charset
      Returns:
      the content
      Throws:
      IOException - In case of an IO error
    • readFileContent

      public String readFileContent(Path file, Charset charset) throws IOException
      Read the file content
      Parameters:
      file - the file
      charset - the charset
      Returns:
      the content
      Throws:
      IOException - In case of an IO error
    • readFileContent

      public String readFileContent(URL url) throws IOException
      Read file content from a url
      Parameters:
      url - the url
      Returns:
      the content
      Throws:
      IOException - In case of an IO error
    • writeFileContent

      public void writeFileContent(Path file, String content) throws IOException
      Write the file content
      Parameters:
      file - the file
      content - the content
      Throws:
      IOException - In case of an IO error
    • writeFileContent

      public void writeFileContent(File file, String content) throws IOException
      Write the file content
      Parameters:
      file - the file
      content - the content
      Throws:
      IOException - In case of an IO error
    • writeFileContent

      public void writeFileContent(File file, Charset charset, String content) throws IOException
      Write the file content
      Parameters:
      file - the file
      charset - the charset
      content - the content
      Throws:
      IOException - In case of an IO error
    • writeFileContent

      public void writeFileContent(Path file, Charset charset, String content) throws IOException
      Write the file content
      Parameters:
      file - the file
      charset - the charset
      content - the content
      Throws:
      IOException - In case of an IO error