Package de.kosmos_lab.utils
Class FileUtils
java.lang.Object
de.kosmos_lab.utils.FileUtils
public class FileUtils extends Object
Helper Class that is used to handle File based tasks
-
Constructor Summary
Constructors Constructor Description FileUtils() -
Method Summary
Modifier and Type Method Description static booleandeleteDirectory(File directory)deletes a directory, recursive!static booleanmakeDirsForFile(File file)create all parent directories for the current filestatic byte[]readBinary(File file)reads a binary filestatic byte[]readBinary(String filename)read a binary filestatic StringreadFile(File file)static StringreadFile(File file, Charset charset)reads a text based filestatic StringreadFile(String filename)static StringreadFile(String filename, String charset)static StringreadFile(String filename, Charset charset)static StringreplaceEnding(File file, String s)static StringreplaceEnding(String path, String s)static voidwriteToFile(File file, byte[] bytes)Write the given bytes to the file, and use the charsetstatic voidwriteToFile(File filename, String text)writes the text to the file, uses UTF-8static voidwriteToFile(File filename, String content, String charset)static voidwriteToFile(File file, String text, Charset charset)static voidwriteToFile(String filename, byte[] bytes)writes the bytes to a given filename, encoded in UTF-8static voidwriteToFile(String filename, String text)writes the text to a given filename, encoded in UTF-8static voidwriteToFile(String filename, String text, String charset)writes the bytes to a given filename, with a given charsetstatic voidwriteToFile(String filename, String text, Charset charset)writes the bytes to a given filename, with a given charset
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
deleteDirectory
deletes a directory, recursive!- Parameters:
directory- the directory to be deleted- Returns:
- Throws:
IllegalArgumentException
-
makeDirsForFile
create all parent directories for the current file/test/foo/bar.txt -> /test/ and /test/foo will be created - if they are needed- Parameters:
file- the file for which to create the parent structure- Returns:
-
readBinary
reads a binary file- Parameters:
file- the file to read- Returns:
- Throws:
IOException
-
readBinary
read a binary file- Parameters:
filename- the filename- Returns:
- the binary content of the file
- Throws:
FileNotFoundException- if the file could not be foundIOException
-
readFile
reads a text based file- Parameters:
file- the file to readcharset- the charset to use- Returns:
- a String containing the contents of the File
- Throws:
IOException
-
readFile
- Parameters:
filename-- Returns:
- Throws:
FileNotFoundExceptionIOException
-
readFile
- Throws:
IOException
-
readFile
public static String readFile(@Nonnull String filename, @Nonnull String charset) throws IOException- Throws:
IOException
-
readFile
public static String readFile(@Nonnull String filename, @Nonnull Charset charset) throws IOException- Throws:
IOException
-
replaceEnding
- Throws:
IOException
-
replaceEnding
-
writeToFile
Write the given bytes to the file, and use the charset- Parameters:
file-bytes-- Throws:
IOException
-
writeToFile
public static void writeToFile(@Nonnull File file, @Nonnull String text, @Nonnull Charset charset) throws IOException- Throws:
IOException
-
writeToFile
public static void writeToFile(@Nonnull File filename, @Nonnull String content, @Nonnull String charset) throws IOException- Throws:
IOException
-
writeToFile
writes the text to the file, uses UTF-8- Parameters:
filename-text-- Throws:
IOException
-
writeToFile
writes the bytes to a given filename, encoded in UTF-8- Parameters:
filename-bytes-- Throws:
IOException
-
writeToFile
writes the text to a given filename, encoded in UTF-8- Parameters:
filename-text-- Throws:
IOException
-
writeToFile
public static void writeToFile(@Nonnull String filename, @Nonnull String text, @Nonnull Charset charset) throws IOExceptionwrites the bytes to a given filename, with a given charset- Parameters:
filename-text-- Throws:
IOException
-
writeToFile
public static void writeToFile(@Nonnull String filename, @Nonnull String text, @Nonnull String charset) throws IOExceptionwrites the bytes to a given filename, with a given charset- Parameters:
filename-text-- Throws:
IOException
-