Class FileIO


  • public class FileIO
    extends Object
    Provides file IO tools.
    • Method Detail

      • copy

        public static void copy​(InputStream is,
                                OutputStream os)
                         throws IOException
        Copies an input stream to an output stream. In Java 9 or later, use is.transferTo(OutputStream).
        Parameters:
        is - the input stream
        os - the output stream
        Throws:
        IOException - if IO fails
      • createTempFile

        public static File createTempFile()
                                   throws IOException
        Creates a temp file.
        Returns:
        returns a the created file
        Throws:
        IOException - if IO fails
      • createTempDir

        public static File createTempDir()
                                  throws IOException
        Creates a temp folder.
        Returns:
        returns the created folder
        Throws:
        IOException - if IO fails
      • copyRecursive

        public static void copyRecursive​(File f,
                                         File out)
        Copies a folder recursively.
        Parameters:
        f - the source folder
        out - the destination folder
      • deleteRecursive

        public static void deleteRecursive​(File f)
        Deletes a folder recursively.
        Parameters:
        f - the folder to delete
      • diff

        public static long diff​(InputStream f1,
                                InputStream f2)
                         throws IOException
        Compares the input streams binary.
        Parameters:
        f1 - the first input stream
        f2 - the second input stream
        Returns:
        returns -1 if the streams are equal, byte position where first difference occurred otherwise
        Throws:
        IOException - if IO fails
      • listFilesRecursive

        public static Collection<File> listFilesRecursive​(File dir,
                                                          String ext)
        Lists files in the specified folder and sub folders having the specified extension. For non-recursive file listing, use: dir.listFiles((parent, name)->name.endsWith(ext));
        Parameters:
        dir - the folder to start search
        ext - the file extensions to find
        Returns:
        returns a list of files
      • toURL

        public static URL[] toURL​(File[] files)
        Converts an array of File objects into URL's.
        Parameters:
        files - the files to convert
        Returns:
        returns an array of URL's