Package com.github.toolarium.common.util
Class FileUtil
java.lang.Object
com.github.toolarium.common.util.FileUtil
Defines a file utility.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if a given file existextractURLPath(URL url) Extract the path from an urlstatic FileUtilGet the instancebooleanisReadable(String fileName) Checks whether the given file or directory is readable.booleanisWritable(String fileName) Checks whether the given file or directory is writable.readFileContent(File file) Read the file contentreadFileContent(File file, Charset charset) Read the file contentreadFileContent(URL url) Read file content from a urlreadFileContent(Path file) Read the file contentreadFileContent(Path file, Charset charset) Read the file contentbooleanremoveDirectory(File dir) Deletes all files and sub directories under dir.booleanremoveDirectory(Path dir) Deletes all files and sub directories under dir.booleanremoveFile(File file) Removes a filebooleanremoveFile(String fileName) Removes a filesimplifyPath(String path) Simplify a given pathSlashify the pathvoidwriteFileContent(File file, String content) Write the file contentvoidwriteFileContent(File file, Charset charset, String content) Write the file contentvoidwriteFileContent(Path file, String content) Write the file contentvoidwriteFileContent(Path file, Charset charset, String content) Write the file content
-
Field Details
-
SLASH
public static final char SLASH- See Also:
-
BACKSLASH
public static final char BACKSLASH- See Also:
-
SLASH_STR
- See Also:
-
BACKSLASH_STR
- See Also:
-
-
Method Details
-
getInstance
Get the instance- Returns:
- the instance
-
simplifyPath
Simplify a given path- Parameters:
path- the path to simplify- Returns:
- the path
-
slashify
Slashify the path- Parameters:
path- the path- Returns:
- the prepared path
-
existFile
Check if a given file exist- Parameters:
fileName- the filename- Returns:
- true if the file exist otherwise false
-
isReadable
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
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
Removes a file- Parameters:
fileName- the file to remove- Returns:
- returns true if all deletions were successful.
-
removeFile
Removes a file- Parameters:
file- the file to remove- Returns:
- removes a file
-
removeDirectory
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
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
Extract the path from an url- Parameters:
url- the url- Returns:
- the path
-
readFileContent
Read the file content- Parameters:
file- the file- Returns:
- the content
- Throws:
IOException- In case of an IO error
-
readFileContent
Read the file content- Parameters:
file- the file- Returns:
- the content
- Throws:
IOException- In case of an IO error
-
readFileContent
Read the file content- Parameters:
file- the filecharset- the charset- Returns:
- the content
- Throws:
IOException- In case of an IO error
-
readFileContent
Read the file content- Parameters:
file- the filecharset- the charset- Returns:
- the content
- Throws:
IOException- In case of an IO error
-
readFileContent
Read file content from a url- Parameters:
url- the url- Returns:
- the content
- Throws:
IOException- In case of an IO error
-
writeFileContent
Write the file content- Parameters:
file- the filecontent- the content- Throws:
IOException- In case of an IO error
-
writeFileContent
Write the file content- Parameters:
file- the filecontent- the content- Throws:
IOException- In case of an IO error
-
writeFileContent
Write the file content- Parameters:
file- the filecharset- the charsetcontent- the content- Throws:
IOException- In case of an IO error
-
writeFileContent
Write the file content- Parameters:
file- the filecharset- the charsetcontent- the content- Throws:
IOException- In case of an IO error
-