Class Files

java.lang.Object
dev.xdpxi.xdlib.api.Files

public class Files extends Object
Utility class for performing common file operations such as creation, deletion, reading, and compression.
  • Constructor Details

    • Files

      public Files()
  • Method Details

    • deleteFolder

      public static void deleteFolder(Path dir) throws IOException
      Deletes the specified folder and its contents recursively.
      Parameters:
      dir - the path to the directory to be deleted.
      Throws:
      IOException - if an I/O error occurs during the operation.
    • deleteFile

      public static void deleteFile(Path file) throws IOException
      Deletes a specified file.
      Parameters:
      file - the path to the file to be deleted.
      Throws:
      IOException - if the file cannot be deleted.
    • createFolder

      public static void createFolder(Path folder) throws IOException
      Creates a directory, including any necessary but nonexistent parent directories.
      Parameters:
      folder - the path to the directory to be created.
      Throws:
      IOException - if an I/O error occurs.
    • createFile

      public static void createFile(Path file) throws IOException
      Creates a new empty file.
      Parameters:
      file - the path to the file to be created.
      Throws:
      IOException - if an I/O error occurs.
    • writeToFile

      public static void writeToFile(File file, String content) throws IOException
      Writes the specified content to a file.
      Parameters:
      file - the file to write to.
      content - the content to write.
      Throws:
      IOException - if an I/O error occurs.
    • readFile

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

      public static void compressFile(String filePath, String zipFilePath) throws IOException
      Compresses a file into a ZIP archive.
      Parameters:
      filePath - the path to the file to be compressed.
      zipFilePath - the path to the output ZIP file.
      Throws:
      IOException - if an I/O error occurs.
    • uncompressFile

      public static void uncompressFile(String zipFilePath, String outputDir) throws IOException
      Extracts a ZIP file to the specified output directory.
      Parameters:
      zipFilePath - the path to the ZIP file to be extracted.
      outputDir - the path to the output directory.
      Throws:
      IOException - if an I/O error occurs.
    • exists

      public static boolean exists(String filePath)
      Checks whether a file exists at the specified path.
      Parameters:
      filePath - the path to check.
      Returns:
      true if the file exists; false otherwise.