Package dev.xdpxi.xdlib.api
Class Files
java.lang.Object
dev.xdpxi.xdlib.api.Files
Utility class for performing common file operations such as creation, deletion, reading, and compression.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcompressFile(String filePath, String zipFilePath) Compresses a file into a ZIP archive.static voidcreateFile(Path file) Creates a new empty file.static voidcreateFolder(Path folder) Creates a directory, including any necessary but nonexistent parent directories.static voiddeleteFile(Path file) Deletes a specified file.static voiddeleteFolder(Path dir) Deletes the specified folder and its contents recursively.static booleanChecks whether a file exists at the specified path.static StringReads the content of a file as a string.static voiduncompressFile(String zipFilePath, String outputDir) Extracts a ZIP file to the specified output directory.static voidwriteToFile(File file, String content) Writes the specified content to a file.
-
Constructor Details
-
Files
public Files()
-
-
Method Details
-
deleteFolder
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
Deletes a specified file.- Parameters:
file- the path to the file to be deleted.- Throws:
IOException- if the file cannot be deleted.
-
createFolder
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
Creates a new empty file.- Parameters:
file- the path to the file to be created.- Throws:
IOException- if an I/O error occurs.
-
writeToFile
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
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
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
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
Checks whether a file exists at the specified path.- Parameters:
filePath- the path to check.- Returns:
trueif the file exists;falseotherwise.
-