Package io.github.connellite.util
Class FileSystemUtils
java.lang.Object
io.github.connellite.util.FileSystemUtils
Utility methods for working with the file system.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyRecursively(File src, File dest) Recursively copy the contents of thesrcfile/directory to thedestfile/directory.static voidcopyRecursively(Path src, Path dest) Recursively copy the contents of thesrcfile/directory to thedestfile/directory.static booleandeleteRecursively(File root) Delete the suppliedFile- for directories, recursively delete any nested directories or files as well.static booleandeleteRecursively(Path root) Delete the suppliedPath- for directories, recursively delete any nested directories or files as well.static voidmoveRecursively(File src, File dest) Recursively move the contents of thesrcfile/directory to thedestfile/directory.static voidmoveRecursively(Path src, Path dest) Recursively move the contents of thesrcfile/directory to thedestfile/directory.static byte[]Readsinto EOF and returns the collected bytes.readAllLines(Path path) Read the lines of a file and return it as a stream using the platform default charset.readAllLines(Path path, Charset charset) Read the lines of a file and return it as a stream.
-
Constructor Details
-
FileSystemUtils
public FileSystemUtils()
-
-
Method Details
-
deleteRecursively
Delete the suppliedFile- for directories, recursively delete any nested directories or files as well.Note: Like
File.delete(), this method does not throw any exception but rather silently returnsfalsein case of I/O errors. Consider usingdeleteRecursively(Path)for NIO-style handling of I/O errors, clearly differentiating between non-existence and failure to delete an existing file.- Parameters:
root- the rootFileto delete- Returns:
trueif theFilewas successfully deleted, otherwisefalse
-
deleteRecursively
Delete the suppliedPath- for directories, recursively delete any nested directories or files as well.- Parameters:
root- the rootPathto delete- Returns:
trueif thePathexisted and was deleted, orfalseif it did not exist- Throws:
IOException- in the case of I/O errors
-
copyRecursively
Recursively copy the contents of thesrcfile/directory to thedestfile/directory.- Parameters:
src- the source directorydest- the destination directory- Throws:
IOException- in the case of I/O errors
-
copyRecursively
Recursively copy the contents of thesrcfile/directory to thedestfile/directory.- Parameters:
src- the source directorydest- the destination directory- Throws:
IOException- in the case of I/O errors
-
moveRecursively
Recursively move the contents of thesrcfile/directory to thedestfile/directory.- Parameters:
src- the source directorydest- the destination directory- Throws:
IOException- in the case of I/O errors
-
moveRecursively
Recursively move the contents of thesrcfile/directory to thedestfile/directory.- Parameters:
src- the source directorydest- the destination directory- Throws:
IOException- in the case of I/O errors
-
readAllLines
Read the lines of a file and return it as a stream using the platform default charset.- Parameters:
path- File path to read- Returns:
- The lines as a stream
-
readAllLines
Read the lines of a file and return it as a stream.- Parameters:
path- File path to readcharset- Charset to decode bytes as characters- Returns:
- The lines as a stream
-
readAllBytes
Readsinto EOF and returns the collected bytes. Does not close the stream.- Parameters:
in- stream to read; must not benull- Returns:
- all remaining bytes (empty if the stream is already at EOF)
- Throws:
IOException- if reading fails
-