Class FileUtils

java.lang.Object
org.apache.maven.shared.utils.io.FileUtils

public class FileUtils extends Object
This class provides basic facilities for manipulating files and file paths.

Path-related methods

Methods exist to retrieve the components of a typical file path. For example /www/hosted/mysite/index.html, can be broken into:

File-related methods

There are methods to create a File from a URL, copy a File to another File, copy a URL's contents to a File, as well as methods to delete and clean a directory.

Common File manipulation routines.

Taken from the commons-utils repo. Also code from Alexandria's FileUtils. And from Avalon Excalibur's IO. And from Ant.

Author:
Kevin A. Burton, Scott Sanders, Daniel Rall, Christoph.Reck, Peter Donald, Jeff Turner
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Deprecated.
    use org.apache.maven.shared.filtering.FilterWrapper
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Protected constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    cleanDirectory(File directory)
    Deprecated.
    use org.apache.commons.io.FileUtils.cleanDirectory()
    static boolean
    contentEquals(File file1, File file2)
    Deprecated.
    use org.apache.commons.io.FileUtils.contentEquals()
    static void
    copyDirectory(File sourceDirectory, File destinationDirectory)
    Deprecated.
    use org.apache.commons.io.FileUtils.copyDirectory()
    static void
    copyDirectory(File sourceDirectory, File destinationDirectory, String includes, String excludes)
    Deprecated.
    use org.apache.commons.io.FileUtils.copyDirectory()
    static void
    copyDirectoryStructure(File sourceDirectory, File destinationDirectory)
    Deprecated.
    use org.apache.commons.io.FileUtils.copyDirectory()
    static void
    copyFile(File source, File destination)
    Deprecated.
    use java.nio.file.Files.copy(source.toPath(), destination.toPath(), LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING)
    static void
    copyFile(File from, File to, String encoding, FileUtils.FilterWrapper... wrappers)
    Deprecated.
    use org.apache.maven.shared.filtering.FilteringUtils.copyFile() instead
    static void
    copyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite)
    Deprecated.
    use org.apache.maven.shared.filtering.FilteringUtils.copyFile() instead
    static void
    copyFileToDirectory(File source, File destinationDirectory)
    Deprecated.
    use org.apache.commons.io.FileUtils.copyFileToDirectory()
    static void
    copyURLToFile(URL source, File destination)
    Deprecated.
    use java.nio.file.Files.copy(source.openStream(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)
    static File
    createSymbolicLink(File symlink, File target)
    Create a new symbolic link, possibly replacing an existing symbolic link.
    static File
    createTempFile(String prefix, String suffix, File parentDir)
    Deprecated.
    use java.nio.file.Files.createTempFile()
    static void
    delete(File file)
    Deprecated.
    use java.nio.file.Files.delete(file.toPath())
    static void
    deleteDirectory(File directory)
    Deprecated.
    use org.apache.commons.io.FileUtils.deleteDirectory()
    static void
    Deprecated.
    use org.apache.commons.io.FileUtils.deleteDirectory()
    static boolean
    Deprecated.
    use java.nio.file.Files.delete(file.toPath())
    static String
    Deprecated.
    use Paths.get(path).getParent().getName()
    static String
    Deprecated.
    use org.apache.commons.io.FilenameUtils.getExtension
    static void
    fileAppend(String fileName, String data)
    Deprecated.
    use java.nio.file.Files.write(filename, data.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE)
    static void
    fileAppend(String fileName, String encoding, String data)
    Deprecated.
    use java.nio.file.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)
    static void
    fileDelete(String fileName)
    Deprecated.
    use Files.delete(Paths.get(fileName))
    static boolean
    fileExists(String fileName)
    Deprecated.
    use java.io.File.exists()
    static String
    Deprecated.
    use Paths.get(path).getName()
    static String
    fileRead(File file)
    Deprecated.
    use new String(java.nio.file.Files.readAllBytes(file.toPath()))
    static String
    fileRead(File file, String encoding)
    Deprecated.
    use new String(java.nio.file.Files.readAllBytes(file.toPath()), encoding)
    static String
    Deprecated.
    use new String(java.nio.file.Files.readAllBytes(file))
    static String[]
    Deprecated.
    use java.nio.file.Files.readAllLines()
    static void
    fileWrite(File file, String encoding, String data)
    Deprecated.
    use java.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)
    static void
    fileWrite(String fileName, String data)
    Deprecated.
    use java.nio.file.Files.write(filename, data.getBytes(), StandardOpenOption.CREATE)
    static void
    fileWrite(String fileName, String encoding, String data)
    Deprecated.
    use java.nio.file.Files.write(Paths.get(filename), data.getBytes(encoding), StandardOpenOption.CREATE)
    static void
    fileWriteArray(File file, String... data)
    Deprecated.
    use java.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)
    static void
    fileWriteArray(File file, String encoding, String... data)
    Deprecated.
    use java.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)
    static void
    Deprecated.
    use org.apache.commons.io.FileUtils.deleteQuietly()
    static void
    Deprecated.
    use org.apache.commons.io.FileUtils.deleteQuietly()
    static void
    Deprecated.
    use org.apache.commons.io.FileUtils.forceMkdir()
    static String[]
     
    static List<String>
     
    static String
     
    static List<String>
    getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir)
    Return the paths to the subdirectories in a directory, relative to the base directory.
    static List<String>
    getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive)
    Return the paths to the subdirectories in a directory, relative to the base directory.
    static String
    getExtension(String filename)
    Deprecated.
    use org.apache.commons.io.FilenameUtils.getExtension()
    static List<String>
    getFileAndDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories)
    Return the paths to the files in a directory, relative to the base directory.
    static List<String>
    getFileNames(File directory, String includes, String excludes, boolean includeBasedir)
    Return a list of the files inside a base directory as relative paths from the base.
    static List<File>
    getFiles(File directory, String includes, String excludes)
    Return a list of the files inside a base directory as relative paths from the base, using inclusion and exclusion Ant patterns, including the directory name in each of the files.
    static List<File>
    getFiles(File directory, String includes, String excludes, boolean includeBasedir)
    Return a list of the files inside a base directory as relative paths from the base, using inclusion and exclusion Ant patterns.
    static String[]
    getFilesFromExtension(String directory, String... extensions)
    Given a directory and an array of extensions return an array of compliant files.
    static boolean
    Deprecated.
    use java.nio.file.Files.isSymbolicLink(file.toPath())
    static boolean
    Deprecated.
    use java.nio.file.Files.isSymbolicLink(file.toPath())
    static List<String>
    loadFile(File file)
    Deprecated.
    assumes the platform default character set
    static void
    Deprecated.
    use java.nio.file.Files.createDirectories(Paths.get(dir))
    static String
    Deprecated.
    use org.apache.commons.io.FilenameUtils.normalize()
    static String
    Deprecated.
    use org.apache.commons.io.FilenameUtils.removeExtension()
    static void
    rename(File from, File to)
    Deprecated.
    use java.nio.file.Files.move()
    static File
    resolveFile(File baseFile, String filename)
    Resolve a file filename to its canonical form.
    static long
    sizeOfDirectory(File directory)
    Deprecated.
    use org.apache.commons.io.FileUtils.sizeOf()
    static long
    Deprecated.
    use org.apache.commons.io.FileUtils.sizeOf()
    static File
    toFile(URL url)
    Convert from a URL to a File.
    static URL[]
    toURLs(File... files)
    Convert the array of Files into a list of URLs.

    Methods inherited from class java.lang.Object

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

    • FileUtils

      protected FileUtils()
      Protected constructor.
  • Method Details

    • getDefaultExcludes

      public static String[] getDefaultExcludes()
      Returns:
      the default excludes pattern
      See Also:
    • getDefaultExcludesAsList

      public static List<String> getDefaultExcludesAsList()
      Returns:
      the default excludes pattern as list
      See Also:
    • getDefaultExcludesAsString

      public static String getDefaultExcludesAsString()
      Returns:
      the default excludes pattern as comma separated string
      See Also:
    • dirname

      @Deprecated public static String dirname(String path)
      Deprecated.
      use Paths.get(path).getParent().getName()
      Returns the directory path portion of a file specification string. Matches the equally named unix command.
      Parameters:
      path - the file path
      Returns:
      the directory portion excluding the ending file separator
    • filename

      @Deprecated public static String filename(String path)
      Deprecated.
      use Paths.get(path).getName()
      Returns the filename portion of a path.
      Parameters:
      path - the file path
      Returns:
      the filename string with extension
    • extension

      @Deprecated public static String extension(String path)
      Deprecated.
      use org.apache.commons.io.FilenameUtils.getExtension
      Returns the extension portion of a file path. This is everything after the last dot '.' in the path (NOT including the dot).
      Parameters:
      path - the file path
      Returns:
      the extension of the file
    • fileExists

      @Deprecated public static boolean fileExists(String fileName)
      Deprecated.
      use java.io.File.exists()
      Check if a file exists.
      Parameters:
      fileName - the file path
      Returns:
      true if file exists
    • fileRead

      @Deprecated public static String fileRead(String file) throws IOException
      Deprecated.
      use new String(java.nio.file.Files.readAllBytes(file))
      Note: the file content is read with platform encoding.
      Parameters:
      file - the file path
      Returns:
      the file content using the platform encoding
      Throws:
      IOException - if any
    • fileRead

      @Deprecated public static String fileRead(File file) throws IOException
      Deprecated.
      use new String(java.nio.file.Files.readAllBytes(file.toPath()))
      Note: the file content is read with platform encoding.
      Parameters:
      file - the file path
      Returns:
      the file content using the platform encoding
      Throws:
      IOException - if any
    • fileRead

      @Deprecated public static String fileRead(File file, String encoding) throws IOException
      Deprecated.
      use new String(java.nio.file.Files.readAllBytes(file.toPath()), encoding)
      Parameters:
      file - the file path
      encoding - the wanted encoding
      Returns:
      the file content using the specified encoding
      Throws:
      IOException - if any
    • fileReadArray

      @Deprecated public static String[] fileReadArray(File file) throws IOException
      Deprecated.
      use java.nio.file.Files.readAllLines()
      Parameters:
      file - the file path
      Returns:
      the file content lines as String[] using the system default encoding. An empty List if the file doesn't exist.
      Throws:
      IOException - in case of failure
    • fileAppend

      @Deprecated public static void fileAppend(String fileName, String data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(filename, data.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE)
      Appends data to a file. The file is created if it does not exist. Note: the data is written with platform encoding.
      Parameters:
      fileName - the path of the file to write
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileAppend

      @Deprecated public static void fileAppend(String fileName, String encoding, String data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)
      Appends data to a file. The file will be created if it does not exist.
      Parameters:
      fileName - the path of the file to write
      encoding - the encoding of the file
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileWrite

      @Deprecated public static void fileWrite(String fileName, String data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(filename, data.getBytes(), StandardOpenOption.CREATE)
      Writes data to a file. The file will be created if it does not exist. Note: the data is written with platform encoding.
      Parameters:
      fileName - the path of the file to write
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileWrite

      @Deprecated public static void fileWrite(String fileName, String encoding, String data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(Paths.get(filename), data.getBytes(encoding), StandardOpenOption.CREATE)
      Writes data to a file. The file will be created if it does not exist.
      Parameters:
      fileName - the path of the file to write
      encoding - the encoding of the file
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileWrite

      @Deprecated public static void fileWrite(File file, String encoding, String data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)
      Writes data to a file. The file will be created if it does not exist.
      Parameters:
      file - the path of the file to write
      encoding - the encoding of the file
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileWriteArray

      @Deprecated public static void fileWriteArray(File file, String... data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)
      Writes String array data to a file in the systems default encoding. The file will be created if it does not exist.
      Parameters:
      file - the path of the file to write
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileWriteArray

      @Deprecated public static void fileWriteArray(File file, String encoding, String... data) throws IOException
      Deprecated.
      use java.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)
      Writes String array data to a file. The file is created if it does not exist.
      Parameters:
      file - the path of the file to write
      encoding - the encoding of the file
      data - the content to write to the file
      Throws:
      IOException - if any
    • fileDelete

      @Deprecated public static void fileDelete(String fileName)
      Deprecated.
      use Files.delete(Paths.get(fileName))
      Deletes a file.
      Parameters:
      fileName - the path of the file to delete
    • getFilesFromExtension

      public static String[] getFilesFromExtension(String directory, String... extensions)
      Given a directory and an array of extensions return an array of compliant files.

      The given extensions should be like "java" and not like ".java".

      Parameters:
      directory - the path of the directory
      extensions - an array of expected extensions
      Returns:
      an array of files for the wanted extensions
    • mkdir

      @Deprecated public static void mkdir(String dir)
      Deprecated.
      use java.nio.file.Files.createDirectories(Paths.get(dir))
      Simple way to make a directory.
      Parameters:
      dir - the directory to create
      Throws:
      IllegalArgumentException - if the dir contains illegal Windows characters under Windows OS
      See Also:
      • INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
    • contentEquals

      @Deprecated public static boolean contentEquals(File file1, File file2) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.contentEquals()
      Compare the contents of two files to determine if they are equal or not.
      Parameters:
      file1 - the first file
      file2 - the second file
      Returns:
      true if the content of the files are equal or they both don't exist, false otherwise
      Throws:
      IOException - if any
    • toFile

      public static File toFile(URL url)
      Convert from a URL to a File.
      Parameters:
      url - file URL
      Returns:
      the equivalent File object, or null if the URL's protocol is not file
    • toURLs

      public static URL[] toURLs(File... files) throws IOException
      Convert the array of Files into a list of URLs.
      Parameters:
      files - the array of files
      Returns:
      the array of URLs
      Throws:
      IOException - if an error occurs
    • removeExtension

      @Deprecated public static String removeExtension(String filename)
      Deprecated.
      use org.apache.commons.io.FilenameUtils.removeExtension()
      Remove extension from a path. E.g.
       foo.txt    → foo
       a\b\c.jpg  → a\b\c
       a\b\c      → a\b\c
       
      Parameters:
      filename - the path of the file
      Returns:
      the filename minus extension
    • getExtension

      @Deprecated public static String getExtension(String filename)
      Deprecated.
      use org.apache.commons.io.FilenameUtils.getExtension()
      Get extension from a path. E.g.
       foo.txt    → "txt"
       a\b\c.jpg  → "jpg"
       a\b\c      → ""
       
      Parameters:
      filename - the path of the file
      Returns:
      the extension of filename or "" if none
    • copyFileToDirectory

      @Deprecated public static void copyFileToDirectory(File source, File destinationDirectory) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.copyFileToDirectory()
      Copy file from source to destination. If destinationDirectory does not exist, it (and any parent directories) will be created. If a file source in destinationDirectory exists, it will be overwritten.
      Parameters:
      source - an existing File to copy
      destinationDirectory - a directory to copy source into
      Throws:
      IllegalArgumentException - if destinationDirectory isn't a directory
      IOException - if source does not exist, the file in destinationDirectory cannot be written to, or an IO error occurs during copying
      FileNotFoundException - if source isn't a normal file
    • copyFile

      @Deprecated public static void copyFile(File source, File destination) throws IOException
      Deprecated.
      use java.nio.file.Files.copy(source.toPath(), destination.toPath(), LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING)
      Copy file from source to destination. The directories up to destination will be created if they don't already exist. destination will be overwritten if it already exists.
      Parameters:
      source - an existing non-directory File to copy bytes from
      destination - a non-directory File to write bytes to (possibly overwriting)
      Throws:
      IOException - if source does not exist, destination cannot be written to, or an IO error occurs during copying
      FileNotFoundException - if destination is a directory
    • copyURLToFile

      public static void copyURLToFile(URL source, File destination) throws IOException
      Deprecated.
      use java.nio.file.Files.copy(source.openStream(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)
      Copies bytes from the URL source to a file destination. The directories up to destination will be created if they don't already exist. destination will be overwritten if it already exists.
      Parameters:
      source - a URL to copy bytes from
      destination - a non-directory File to write bytes to (possibly overwriting)
      Throws:
      IOException - if
      • source URL cannot be opened
      • destination cannot be written to
      • an IO error occurs during copying
    • normalize

      @Deprecated public static String normalize(String path)
      Deprecated.
      use org.apache.commons.io.FilenameUtils.normalize()
      Normalize a path. Eliminates "/../" and "/./" in a string. Returns null if the ..'s went past the root. Eg:
       /foo//               →     /foo/
       /foo/./              →     /foo/
       /foo/../bar          →     /bar
       /foo/../bar/         →     /bar/
       /foo/../bar/../baz   →     /baz
       //foo//./bar         →     /foo/bar
       /../                 →     null
       
      Parameters:
      path - the path to normalize
      Returns:
      the normalized String, or null if too many ..'s
    • resolveFile

      public static File resolveFile(File baseFile, String filename)
      Resolve a file filename to its canonical form. If filename is relative (doesn't start with /), it is resolved relative to baseFile. Otherwise it is treated as a normal root-relative path.
      Parameters:
      baseFile - where to resolve filename from, if filename is relative
      filename - absolute or relative file path to resolve
      Returns:
      the canonical File of filename
    • forceDelete

      @Deprecated public static void forceDelete(String file) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.deleteQuietly()
      Delete a file. If file is directory, delete it and all sub-directories.
      Parameters:
      file - the file path
      Throws:
      IOException - if any
    • forceDelete

      @Deprecated public static void forceDelete(File file) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.deleteQuietly()
      Delete a file. If file is directory, delete it and all sub-directories.
      Parameters:
      file - a file
      Throws:
      IOException - if any
    • delete

      @Deprecated public static void delete(File file) throws IOException
      Deprecated.
      use java.nio.file.Files.delete(file.toPath())
      Deletes a file.
      Parameters:
      file - the file to delete
      Throws:
      IOException - if the file cannot be deleted
    • deleteLegacyStyle

      @Deprecated public static boolean deleteLegacyStyle(File file)
      Deprecated.
      use java.nio.file.Files.delete(file.toPath())
      Parameters:
      file - the file
      Returns:
      true / false
    • forceMkdir

      @Deprecated public static void forceMkdir(File file) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.forceMkdir()
      Make a directory.
      Parameters:
      file - not null
      Throws:
      IllegalArgumentException - if the file contains illegal Windows characters under Windows OS
      IOException - if a file already exists with the specified name or the directory is unable to be created
      See Also:
      • INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
    • deleteDirectory

      @Deprecated public static void deleteDirectory(String directory) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.deleteDirectory()
      Recursively delete a directory.
      Parameters:
      directory - a directory
      Throws:
      IOException - if any
    • deleteDirectory

      @Deprecated public static void deleteDirectory(File directory) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.deleteDirectory()
      Recursively delete a directory.
      Parameters:
      directory - a directory
      Throws:
      IOException - if any
    • cleanDirectory

      @Deprecated public static void cleanDirectory(File directory) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.cleanDirectory()
      Remove all files from a directory without deleting it.
      Parameters:
      directory - a directory
      Throws:
      IOException - if any. This can leave cleaning in a half-finished state where some but not all files have been deleted.
    • sizeOfDirectory

      @Deprecated public static long sizeOfDirectory(String directory)
      Deprecated.
      use org.apache.commons.io.FileUtils.sizeOf()
      Recursively count size of a directory.
      Parameters:
      directory - a directory
      Returns:
      size of directory in bytes
    • sizeOfDirectory

      @Deprecated public static long sizeOfDirectory(File directory)
      Deprecated.
      use org.apache.commons.io.FileUtils.sizeOf()
      Recursively count size of a directory.
      Parameters:
      directory - a directory
      Returns:
      size of directory in bytes
    • getFiles

      public static List<File> getFiles(File directory, String includes, String excludes) throws IOException
      Return a list of the files inside a base directory as relative paths from the base, using inclusion and exclusion Ant patterns, including the directory name in each of the files. This is recursive and descends into subdirectories. However it does not include the subdirectories themselves in the returned list. This method uses case sensitive file names.
      Parameters:
      directory - the directory to scan
      includes - the Ant includes pattern, comma separated
      excludes - the Ant excludes pattern, comma separated
      Returns:
      a list of File objects
      Throws:
      IOException - never
      See Also:
    • getFiles

      public static List<File> getFiles(File directory, String includes, String excludes, boolean includeBasedir) throws IOException
      Return a list of the files inside a base directory as relative paths from the base, using inclusion and exclusion Ant patterns. This is recursive and descends into subdirectories. However it does not include the subdirectories themselves in the returned list. This method uses case sensitive file names.
      Parameters:
      directory - the directory to scan
      includes - the includes pattern, comma separated
      excludes - the excludes pattern, comma separated
      includeBasedir - true to include the base dir in each file
      Returns:
      a list of File objects
      Throws:
      IOException - never
      See Also:
    • getFileNames

      public static List<String> getFileNames(File directory, String includes, String excludes, boolean includeBasedir) throws IOException
      Return a list of the files inside a base directory as relative paths from the base. This is recursive and descends into subdirectories. However it does not include the subdirectories themselves in the returned list. This method uses case sensitive file names.
      Parameters:
      directory - the directory to scan
      includes - the Ant includes pattern, comma separated
      excludes - the Ant excludes pattern, comma separated
      includeBasedir - true to include the base directory in each String of file
      Returns:
      a list of file names
      Throws:
      IOException - never
    • getDirectoryNames

      public static List<String> getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir) throws IOException
      Return the paths to the subdirectories in a directory, relative to the base directory. This is recursive and descends into subdirectories. This method use case sensitive file name.
      Parameters:
      directory - the base directory to search
      includes - the Ant includes pattern, comma separated
      excludes - the Ant excludes pattern, comma separated
      includeBasedir - true to include the base directory at the start of each path
      Returns:
      a list of relative paths of directories
      Throws:
      IOException - never
    • getDirectoryNames

      public static List<String> getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) throws IOException
      Return the paths to the subdirectories in a directory, relative to the base directory. This is recursive and descends into subdirectories.
      Parameters:
      directory - the base directory to search
      includes - the Ant includes pattern, comma separated
      excludes - the Ant excludes pattern, comma separated
      includeBasedir - true to include the base directory at the start of each path
      isCaseSensitive - true if the includes and excludes are case sensitive
      Returns:
      a list of relative paths of directories
      Throws:
      IOException - never
    • getFileAndDirectoryNames

      public static List<String> getFileAndDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories)
      Return the paths to the files in a directory, relative to the base directory. This is recursive and descends into subdirectories.
      Parameters:
      directory - the directory to scan
      includes - the Ant includes pattern, comma separated
      excludes - the Ant excludes pattern, comma separated
      includeBasedir - true to include the base directory at the start of each path
      isCaseSensitive - true if the includes and excludes are case sensitive
      getFiles - true to include regular files in the list
      getDirectories - true to include directories in the list
      Returns:
      a list of relative paths
    • copyDirectory

      @Deprecated public static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.copyDirectory()
      Copy the contents of a directory into another one.
      Parameters:
      sourceDirectory - the source directory. If the source does not exist, the method simply returns.
      destinationDirectory - the target directory; will be created if it doesn't exist
      Throws:
      IOException - if any
    • copyDirectory

      @Deprecated public static void copyDirectory(File sourceDirectory, File destinationDirectory, String includes, String excludes) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.copyDirectory()
      Copy the contents of a directory into another one.
      Parameters:
      sourceDirectory - the source directory
      destinationDirectory - the target directory
      includes - ant include pattern
      excludes - ant exclude pattern
      Throws:
      IOException - if the source is a file or cannot be copied
      See Also:
    • copyDirectoryStructure

      @Deprecated public static void copyDirectoryStructure(File sourceDirectory, File destinationDirectory) throws IOException
      Deprecated.
      use org.apache.commons.io.FileUtils.copyDirectory()
      Copies an entire directory structure.

      Note:

      • It will include empty directories.
      • The sourceDirectory must exist.
      Parameters:
      sourceDirectory - the existing directory to be copied
      destinationDirectory - the new directory to be created
      Throws:
      IOException - if any
    • rename

      @Deprecated public static void rename(File from, File to) throws IOException
      Deprecated.
      use java.nio.file.Files.move()
      Renames a file, even if that involves crossing file system boundaries.

      This will remove to (if it exists), ensure that to's parent directory exists and move from, which involves deleting from as well.

      Parameters:
      from - the file to move
      to - the new file name
      Throws:
      IOException - if anything bad happens during this process. Note that to may have been deleted already when this happens.
    • createTempFile

      @Deprecated public static File createTempFile(String prefix, String suffix, File parentDir)
      Deprecated.
      use java.nio.file.Files.createTempFile()

      Create a temporary file in a given directory.

      The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.

      The filename is prefixNNNNNsuffix where NNNN is a random number

      This method is different to File.createTempFile(String, String, File) as it doesn't create the file itself. It uses the location pointed to by java.io.tmpdir when the parentDir attribute is null.

      To automatically delete the file created by this method, use the File.deleteOnExit() method.

      Parameters:
      prefix - prefix before the random number
      suffix - file extension; include the '.'
      parentDir - directory to create the temporary file in -java.io.tmpdir used if not specified
      Returns:
      a File reference to the new temporary file
    • copyFile

      @Deprecated public static void copyFile(File from, File to, String encoding, FileUtils.FilterWrapper... wrappers) throws IOException
      Deprecated.
      use org.apache.maven.shared.filtering.FilteringUtils.copyFile() instead
      If wrappers is null or empty, the file will be copied only if to.lastModified() < from.lastModified()
      Parameters:
      from - the file to copy
      to - the destination file
      encoding - the file output encoding (only if wrappers is not empty)
      wrappers - array of FileUtils.FilterWrapper
      Throws:
      IOException - if an IO error occurs during copying or filtering
    • copyFile

      @Deprecated public static void copyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite) throws IOException
      Deprecated.
      use org.apache.maven.shared.filtering.FilteringUtils.copyFile() instead
      If wrappers is null or empty, the file will be copied only if to.lastModified() < from.lastModified() or if overwrite is true
      Parameters:
      from - the file to copy
      to - the destination file
      encoding - the file output encoding (only if wrappers is not empty)
      wrappers - array of FileUtils.FilterWrapper
      overwrite - if true and wrappers is null or empty, the file will be copied even if to.lastModified() < from.lastModified()
      Throws:
      IOException - if an IO error occurs during copying or filtering
    • loadFile

      @Deprecated public static List<String> loadFile(File file) throws IOException
      Deprecated.
      assumes the platform default character set
      Note: the file content is read with platform encoding.
      Parameters:
      file - the file
      Returns:
      a List containing every every line not starting with # and not empty
      Throws:
      IOException - if any
    • isSymbolicLink

      @Deprecated public static boolean isSymbolicLink(File file) throws IOException
      Deprecated.
      use java.nio.file.Files.isSymbolicLink(file.toPath())
      Checks whether a given file is a symbolic link.
      Parameters:
      file - the file to check
      Returns:
      true if symbolic link false otherwise
      Throws:
      IOException - in case of failure
    • isSymbolicLinkForSure

      @Deprecated public static boolean isSymbolicLinkForSure(File file) throws IOException
      Deprecated.
      use java.nio.file.Files.isSymbolicLink(file.toPath())
      Checks whether a given file is a symbolic link.
      Parameters:
      file - the file to check
      Returns:
      true if and only if we reliably can say this is a symlink
      Throws:
      IOException - in case of failure
    • createSymbolicLink

      public static File createSymbolicLink(File symlink, File target) throws IOException
      Create a new symbolic link, possibly replacing an existing symbolic link.
      Parameters:
      symlink - the link name
      target - the target
      Returns:
      the linked file
      Throws:
      IOException - in case of an error
      See Also: