Class FileUtils


  • public final class FileUtils
    extends java.lang.Object
    The FileUtils class provides utility methods to work with files.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copy​(java.io.File sourceLocation, java.io.File targetLocation)
      Copies all data from the source location (file.
      static void copyDirectory​(java.io.File source, java.io.File target)
      Copies all data from the source directory to the target directory.
      static void copyFile​(java.io.File source, java.io.File target)
      Copies all data from the source file to the target file.
      static java.lang.String getFileDir​(java.lang.String fileName)
      Returns the parent directory of the file.
      static java.lang.String getFileExtension​(java.lang.String fileName)
      Returns extension of the file.
      static java.lang.String getNormalizedPath​(java.lang.String filePath)
      Creates normalized file path.
      static java.lang.String getShortFileName​(java.lang.String fileName)
      Returns the short name of the file.
      static java.lang.String getShortFileNameNoExt​(java.lang.String fileName)
      Returns the short name of the file without an extension.
      static boolean isExecutable​(java.io.File file)
      Checks whether the specified file is executable.
      static java.io.BufferedReader newBufferedReader​(java.io.File file)
      Creates new BufferedReader for existing file.
      static java.io.File newFile​(java.lang.String fileName)
      Creates the new file with the specified name.
      static java.io.File newFile​(java.lang.String path, java.lang.String name, java.lang.String ext)
      Creates an empty file with the specified name at the specified path.
      static java.io.PrintWriter newPrintWriter​(java.lang.String path, java.lang.String name, java.lang.String ext)
      Creates new PrintWriter for the new file with the specified parameters.
      • Methods inherited from class java.lang.Object

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

      • getNormalizedPath

        public static java.lang.String getNormalizedPath​(java.lang.String filePath)
        Creates normalized file path.

        In normalized path non-system separators are substituted by system separators.

        Parameters:
        filePath - The path to file.
        Returns:
        The new string that stores the normalized version of the input path.
      • getFileExtension

        public static java.lang.String getFileExtension​(java.lang.String fileName)
        Returns extension of the file.
        Parameters:
        fileName - The file name.
        Returns:
        The file extension.
      • getShortFileName

        public static java.lang.String getShortFileName​(java.lang.String fileName)
        Returns the short name of the file.
        Parameters:
        fileName - The file name.
        Returns:
        The short name of the file.
      • getShortFileNameNoExt

        public static java.lang.String getShortFileNameNoExt​(java.lang.String fileName)
        Returns the short name of the file without an extension.
        Parameters:
        fileName - The file name.
        Returns:
        The short name of the file without an extension.
      • getFileDir

        public static java.lang.String getFileDir​(java.lang.String fileName)
        Returns the parent directory of the file.
        Parameters:
        fileName - The file name.
        Returns:
        The parent directory of the file.
      • copy

        public static void copy​(java.io.File sourceLocation,
                                java.io.File targetLocation)
                         throws java.io.IOException
        Copies all data from the source location (file. directory, etc.) to the target one.
        Parameters:
        sourceLocation - The source location.
        targetLocation - The target location.
        Throws:
        java.io.IOException - when some internal file-related operation is crashed.
      • copyDirectory

        public static void copyDirectory​(java.io.File source,
                                         java.io.File target)
                                  throws java.io.IOException
        Copies all data from the source directory to the target directory.
        Parameters:
        source - The source directory.
        target - The target directory.
        Throws:
        java.io.IOException - when some internal file-related operation is crashed.
      • copyFile

        public static void copyFile​(java.io.File source,
                                    java.io.File target)
                             throws java.io.IOException
        Copies all data from the source file to the target file.
        Parameters:
        source - The source file.
        target - The target file.
        Throws:
        java.io.IOException - when some internal file-related operation is crashed.
      • newFile

        public static java.io.File newFile​(java.lang.String path,
                                           java.lang.String name,
                                           java.lang.String ext)
        Creates an empty file with the specified name at the specified path.
        Parameters:
        path - The path to file.
        name - The file name without an extension.
        ext - The file extension.
        Returns:
        The new file.
      • newFile

        public static java.io.File newFile​(java.lang.String fileName)
        Creates the new file with the specified name.
        Parameters:
        fileName - The file name.
        Returns:
        The new file with the specified name.
      • isExecutable

        public static boolean isExecutable​(java.io.File file)
        Checks whether the specified file is executable.
        Parameters:
        file - The File to be checked.
        Returns:
        true if the specified file exists and can be executed, false otherwise.
      • newPrintWriter

        public static java.io.PrintWriter newPrintWriter​(java.lang.String path,
                                                         java.lang.String name,
                                                         java.lang.String ext)
                                                  throws java.io.IOException
        Creates new PrintWriter for the new file with the specified parameters.
        Parameters:
        path - The path to new file.
        name - The new file name.
        ext - The new file extension.
        Returns:
        The PrintWriter for the new file.
        Throws:
        java.io.IOException - when some internal file-related operation is crashed.
      • newBufferedReader

        public static java.io.BufferedReader newBufferedReader​(java.io.File file)
        Creates new BufferedReader for existing file.
        Parameters:
        file - The processed file.
        Returns:
        The BufferedReader for the file.
        Throws:
        java.io.FileNotFoundException - when file does not exist.