Class FileUtils

java.lang.Object
org.europa.together.utils.FileUtils

public final class FileUtils extends Object
Some helpful stuff for file handling.
  • Method Details

    • inputStreamToByteArray

      public static byte[] inputStreamToByteArray(InputStream input) throws IOException
      Convert an InputStream to an ByteArray.
      Parameters:
      input - as InputStream
      Returns:
      byte[] as Array
      Throws:
      IOException
    • writeStringToFile

      public static boolean writeStringToFile(String content, String destinationFile) throws IOException
      Write a String to a File.It is possible to create an empty file whitout content. DestinationFile is a full qualitied path including the file name. Sample: /home/user/file.txt
      Parameters:
      content - as String
      destinationFile - as String
      Returns:
      true on success
      Throws:
      IOException
    • 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 String
      dimension - as String
      Returns:
      fileSize as double
    • readFileStream

      public static String readFileStream(File file, ByteOrderMark... charset) throws FileNotFoundException, IOException
      Reads the full content of a text file in UTF-8.The second parameter charset is optional.
      Parameters:
      file - as File
      charset - as ByteOrderMark (Optional)
      Returns:
      fileContent as String
      Throws:
      FileNotFoundException
      IOException
    • appendFile

      public static void appendFile(String filePath, String content) throws IOException
      Append content to a given text file at the end of the file in UTF-8.
      Parameters:
      filePath - as String
      content - as String
      Throws:
      IOException
    • copyFile

      public static void copyFile(File source, File destination) throws FileNotFoundException, IOException
      Copy a single File from a source to a destination.
      Parameters:
      source - as File
      destination - as File
      Throws:
      FileNotFoundException
      IOException
    • listFileTree

      public static Set<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:
      a Set of Files