Class FileUtils


  • public class FileUtils
    extends Object
    Helper Class that is used to handle File based tasks
    • Constructor Detail

      • FileUtils

        public FileUtils()
    • Method Detail

      • makeDirsForFile

        public static boolean makeDirsForFile​(@Nonnull
                                              File file)
        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

        @Nonnull
        public static byte[] readBinary​(@Nonnull
                                        File file)
                                 throws IOException
        reads a binary file
        Parameters:
        file - the file to read
        Returns:
        Throws:
        IOException
      • readBinary

        public static byte[] readBinary​(@Nonnull
                                        String filename)
                                 throws IOException
        read a binary file
        Parameters:
        filename - the filename
        Returns:
        the binary content of the file
        Throws:
        FileNotFoundException - if the file could not be found
        IOException
      • readFile

        public static String readFile​(@Nonnull
                                      File file,
                                      @Nonnull
                                      Charset charset)
                               throws IOException
        reads a text based file
        Parameters:
        file - the file to read
        charset - the charset to use
        Returns:
        a String containing the contents of the File
        Throws:
        IOException
      • writeToFile

        public static void writeToFile​(@Nonnull
                                       File file,
                                       @Nonnull
                                       byte[] bytes)
                                throws IOException
        Write the given bytes to the file, and use the charset
        Parameters:
        file -
        bytes -
        Throws:
        IOException
      • writeToFile

        public static void writeToFile​(@Nonnull
                                       File filename,
                                       @Nonnull
                                       String text)
                                throws IOException
        writes the text to the file, uses UTF-8
        Parameters:
        filename -
        text -
        Throws:
        IOException
      • writeToFile

        public static void writeToFile​(@Nonnull
                                       String filename,
                                       @Nonnull
                                       byte[] bytes)
                                throws IOException
        writes the bytes to a given filename, encoded in UTF-8
        Parameters:
        filename -
        bytes -
        Throws:
        IOException
      • writeToFile

        public static void writeToFile​(@Nonnull
                                       String filename,
                                       @Nonnull
                                       String text)
                                throws IOException
        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 IOException
        writes 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 IOException
        writes the bytes to a given filename, with a given charset
        Parameters:
        filename -
        text -
        Throws:
        IOException