Class FileUtil


  • public class FileUtil
    extends java.lang.Object
    A file management API. This Class provide simple and efficient file management methods.
    Since:
    1.0.0
    Author:
    Julien Seinturier - (c) 2009 - JOrigin project - http:/www.jorigin.org
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean copy​(java.io.File source, java.io.File destination)
      Simple copy of a source file to a destination file
      static boolean copyDirectory​(java.io.File source, java.io.File destination)
      Copying recursively a directory to another.
      static boolean deleteDirectory​(java.io.File path)
      Delete recursively a directory.
      static java.util.ArrayList<java.io.File> listFiles​(java.io.File source, java.io.FileFilter filter)
      List recursively a directory and its sub-directories.
      static long size​(java.io.File path)
      Return the file or directory size in byte
      • Methods inherited from class java.lang.Object

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

      • FileUtil

        public FileUtil()
    • Method Detail

      • size

        public static long size​(java.io.File path)
        Return the file or directory size in byte
        Parameters:
        path - the file or directory to check
        Returns:
        the complete size in bytes of the file or directory.
      • deleteDirectory

        public static boolean deleteDirectory​(java.io.File path)
        Delete recursively a directory.
        Parameters:
        path - path to the directory (or file) you want to delete
        Returns:
        true if the delete was successfull and false if the delete was unable to erase all the directory
      • copy

        public static boolean copy​(java.io.File source,
                                   java.io.File destination)
        Simple copy of a source file to a destination file
        Parameters:
        source - the path of the source file
        destination - the path of the destination file
        Returns:
        true if the copy was successfull and false if not
      • copyDirectory

        public static boolean copyDirectory​(java.io.File source,
                                            java.io.File destination)
        Copying recursively a directory to another. If the destination directory does not exist, it is created.
        Parameters:
        source - the source directory (or file to copy)
        destination - the destination directory.
        Returns:
        true if the copy was successfull, false if the copy was unsuccessfull
      • listFiles

        public static java.util.ArrayList<java.io.File> listFiles​(java.io.File source,
                                                                  java.io.FileFilter filter)
        List recursively a directory and its sub-directories.
        Parameters:
        source - the source directory (or file to copy).
        filter - a filter used for accepting files within the list.
        Returns:
        the list of files presents in the directory.