Package org.europa.together.utils
Class FileUtils
- java.lang.Object
-
- org.europa.together.utils.FileUtils
-
public final class FileUtils extends Object
Some helpful stuff for file handling.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendFile(String filePath, String content)
Append content to a given text file at the end of the file in UTF-8.static void
copyFile(File source, File destination)
Copy a File A from a source to a destination.static long
getFileSize(String filePath, String dimension)
Get the bytes of file.static Collection<File>
listFileTree(File directory)
Discover a directory and all subdirectories to collect their the files in a List.static String
readFileStream(File file, ByteOrderMark... charset)
Reads the full content of a text file in UTF-8.static boolean
writeStringToFile(String content, String destinationFile)
Write a string to a File.
-
-
-
Method Detail
-
writeStringToFile
public static boolean writeStringToFile(String content, String destinationFile)
Write a string to a File.- Parameters:
content
- as StringdestinationFile
- as String- Returns:
- true on success
-
getFileSize
public static long getFileSize(String filePath, String dimension)
Get the bytes of file. It is also possible to choose a dimension for the file size. The following options for dimension are available: kilo, mega, giga and tera.- Parameters:
filePath
- as Stringdimension
- as String- Returns:
- fileSize as double
-
readFileStream
public static String readFileStream(File file, ByteOrderMark... charset)
Reads the full content of a text file in UTF-8. The second parameter charset is optional.- Parameters:
file
- as Filecharset
- as ByteOrderMark (Optional)- Returns:
- fileContent as String
-
appendFile
public static void appendFile(String filePath, String content)
Append content to a given text file at the end of the file in UTF-8.- Parameters:
filePath
- as Stringcontent
- as String
-
copyFile
public static void copyFile(File source, File destination) throws IOException
Copy a File A from a source to a destination.- Parameters:
source
- as Filedestination
- as File- Throws:
IOException
- on failure
-
listFileTree
public static Collection<File> listFileTree(File directory)
Discover a directory and all subdirectories to collect their the files in a List. The list entries are the full path, the filename with file extension. Empty directories will not listed.
Example /usr/home/john/file.txt- Parameters:
directory
- as File- Returns:
- Collection of Files
-
-