Class FileHelper


  • public final class FileHelper
    extends Object
    Helper-class for handling with files.
    • Method Detail

      • readFile

        public static String readFile​(File f)
        Reads in a file and converts it to a string.
        Parameters:
        f - = file to be read in and converted.
        Returns:
      • readFile

        public static String readFile​(InputStream io)
        Reads in a file and converts it to a string.
        Parameters:
        io -
        Returns:
      • readFile

        public static String readFile​(Reader reader)
        Reads in a file and converts it to a string.
        Parameters:
        reader -
        Returns:
      • readFile

        public static String readFile​(File f,
                                      String charset)
        Reads in a file and converts it to a string.
        Parameters:
        f - = file to be read in and converted.
        Returns:
      • readFile

        public static String readFile​(InputStream io,
                                      String charset)
        Reads in a file and converts it to a string.
        Parameters:
        io -
        charset -
        Returns:
      • getManifestFile

        public static Manifest getManifestFile​(File jarfile)
                                        throws IOException
        Returns the Manifest-data from the given jarfile.
        Parameters:
        jarfile -
        Returns:
        Throws:
        IOException
      • writeStringToFile

        public static boolean writeStringToFile​(File file,
                                                String text)
      • byteArrayToFile

        public static void byteArrayToFile​(byte[] bytes,
                                           File outputFile)
        Saves all bytes into the given file.
        Parameters:
        bytes - = byte-arry to save into the save
        outputFile - = file which will be overwritten with the given byte-arry
      • byteArrayToFile

        public static byte[] byteArrayToFile​(File file)
        Converts the file to a byte[].
        Parameters:
        file -
        Returns:
      • generateUniqueFile

        public static File generateUniqueFile​(File file,
                                              String mimetype)
                                       throws IOException
        Generates a file with the given mimetype and returns this new file back.
        If the passed file is null, null will be returned!

        Example:
        If "File.txt" already exists then simply "File(1).txt" will be created,
        if this also exists, a value "File(x).txt" is tried until one of them works.
        Parameters:
        file - = File to create.
        mimetype - = Mimetype of the file to create.
        Returns:
        Throws:
        IOException
      • getAllFilesRecursivly

        public static List<File> getAllFilesRecursivly​(File pFile,
                                                       String suffix)
        Returns all files recursivly within the pFile for the specific suffix in a list.
        Parameters:
        pFile -
        suffix -
        Returns:
      • getOnlyFilename

        public static String getOnlyFilename​(File file)
        Return only the filename without suffix.
        Parameters:
        file -
        Returns:
      • bytesToHex

        public static String bytesToHex​(byte[] bytes)