Class FileUtil


  • public final class FileUtil
    extends java.lang.Object
    This class contains some useful static methods for handling files
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyFile​(java.io.File source, java.io.File destination)
      Copy a file in the File system.
      static void createDir​(java.io.File dir, boolean globalAccess)
      creates the given dir and enables access for all users if wanted.
      static boolean deleteDir​(java.io.File dir)
      recursively deletes the dir and all its content
      static java.util.Set<java.io.File> searchInFor​(java.nio.file.Path root, java.util.function.Predicate<? super java.nio.file.Path> filterPredicate)  
      static java.util.List<java.lang.String> tail​(java.io.File file, int requestedNumberOfLines)
      Returns the last N lines of the given file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createDir

        public static void createDir​(java.io.File dir,
                                     boolean globalAccess)
        creates the given dir and enables access for all users if wanted.
        Parameters:
        dir - the dir to create
        globalAccess - if true, give rights to all users, if false permissions are not changed
      • deleteDir

        public static boolean deleteDir​(java.io.File dir)
        recursively deletes the dir and all its content
        Parameters:
        dir - the dir to delete
        Returns:
        true if successful, false otherwise.
      • copyFile

        public static void copyFile​(java.io.File source,
                                    java.io.File destination)
                             throws java.io.IOException
        Copy a file in the File system. Uses FileReader and FileWriter to copy the files content.
        Parameters:
        source - the source file
        destination - the destination file to save the content to
        Throws:
        java.io.IOException
      • tail

        public static java.util.List<java.lang.String> tail​(java.io.File file,
                                                            int requestedNumberOfLines)
        Returns the last N lines of the given file. If the file has less lines than the requested ones, it will return all the lines of the file. Thus, the returned list can also be empty.
        Parameters:
        file - the file from which to retrieve the last lines
        requestedNumberOfLines - the number of lines to retrieve
        Returns:
        the last lines, as requested.
      • searchInFor

        public static java.util.Set<java.io.File> searchInFor​(java.nio.file.Path root,
                                                              java.util.function.Predicate<? super java.nio.file.Path> filterPredicate)