Class FileUtils

java.lang.Object
com.toxicrain.rainengine.util.FileUtils

public class FileUtils extends Object
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • getFileFromResourceAsStream

      @Deprecated public static InputStream getFileFromResourceAsStream(String filePath)
      Deprecated.
    • readFile

      public static String readFile(String filePath) throws IOException
      Utility method to read the file content into a string
      Parameters:
      filePath - the path to the file
      Returns:
      the content of the file as a string
      Throws:
      IOException - if an I/O error occurs
    • getFileSize

      public static long getFileSize(String filePath)
      Utility method to get the size of a file as a long.
      Parameters:
      filePath - the path to the file
      Returns:
      the size of the file (in bytes) as a long
    • getUserHome

      public static String getUserHome()
      Returns:
      System.getProperty("user.home")
    • getUserDir

      public static String getUserDir()
    • getCurrentWorkingDirectory

      public static String getCurrentWorkingDirectory(String relativePath)
      Converts a relative path to an absolute path based on the current working directory. If the path has been converted before, it returns the cached value.
      Parameters:
      relativePath - the relative path to convert
      Returns:
      the absolute path as a String
    • getCurrentWorkingDirectory

      public static String getCurrentWorkingDirectory(String primaryPath, String fallbackPath)
      Converts a relative path to an absolute path based on the current working directory. Checks if the first path exists; if not, it uses the second path.
      Parameters:
      primaryPath - the primary path to check and convert
      fallbackPath - the fallback path to use if the primary path doesn't exist
      Returns:
      the absolute path as a String
    • writeFile

      public static void writeFile(String filePath, String data) throws IOException
      Throws:
      IOException
    • ioResourceToByteBuffer

      public static ByteBuffer ioResourceToByteBuffer(String resource) throws IOException
      Throws:
      IOException