Class FileUtils
- java.lang.Object
-
- org.apache.maven.shared.utils.io.FileUtils
-
public class FileUtils extends java.lang.ObjectThis 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:/www/hosted/mysite/index-- retrievable throughremoveExtension(java.lang.String)html-- retrievable throughgetExtension(java.lang.String)
File-related methods
There are methods to create a
File from a URL, copy aFile to another File, copy aURL's contents to a File, as well as methods todeleteandcleana directory.Common
Filemanipulation routines.Taken from the commons-utils repo. Also code from Alexandria's FileUtils. And from Avalon Excalibur's IO. And from Ant.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileUtils.FilterWrapperDeprecated.useorg.apache.maven.shared.filtering.FilterWrapper
-
Constructor Summary
Constructors Modifier Constructor Description protectedFileUtils()Protected constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcleanDirectory(java.io.File directory)Deprecated.useorg.apache.commons.io.FileUtils.cleanDirectory()static booleancontentEquals(java.io.File file1, java.io.File file2)Deprecated.useorg.apache.commons.io.FileUtils.contentEquals()static voidcopyDirectory(java.io.File sourceDirectory, java.io.File destinationDirectory)Deprecated.useorg.apache.commons.io.FileUtils.copyDirectory()static voidcopyDirectory(java.io.File sourceDirectory, java.io.File destinationDirectory, java.lang.String includes, java.lang.String excludes)Deprecated.useorg.apache.commons.io.FileUtils.copyDirectory()static voidcopyDirectoryStructure(java.io.File sourceDirectory, java.io.File destinationDirectory)Deprecated.useorg.apache.commons.io.FileUtils.copyDirectory()static voidcopyFile(java.io.File source, java.io.File destination)Deprecated.usejava.nio.file.Files.copy(source.toPath(), destination.toPath(), LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING)static voidcopyFile(java.io.File from, java.io.File to, java.lang.String encoding, FileUtils.FilterWrapper... wrappers)Deprecated.useorg.apache.maven.shared.filtering.FilteringUtils.copyFile()insteadstatic voidcopyFile(java.io.File from, java.io.File to, java.lang.String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite)Deprecated.useorg.apache.maven.shared.filtering.FilteringUtils.copyFile()insteadstatic voidcopyFileToDirectory(java.io.File source, java.io.File destinationDirectory)Deprecated.useorg.apache.commons.io.FileUtils.copyFileToDirectory()static voidcopyURLToFile(java.net.URL source, java.io.File destination)Deprecated.usejava.nio.file.Files.copy(source.openStream(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)static java.io.FilecreateSymbolicLink(java.io.File symlink, java.io.File target)Create a new symbolic link, possibly replacing an existing symbolic link.static java.io.FilecreateTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File parentDir)Deprecated.usejava.nio.file.Files.createTempFile()static voiddelete(java.io.File file)Deprecated.usejava.nio.file.Files.delete(file.toPath())static voiddeleteDirectory(java.io.File directory)Deprecated.useorg.apache.commons.io.FileUtils.deleteDirectory()static voiddeleteDirectory(java.lang.String directory)Deprecated.useorg.apache.commons.io.FileUtils.deleteDirectory()static booleandeleteLegacyStyle(java.io.File file)Deprecated.usejava.nio.file.Files.delete(file.toPath())static java.lang.Stringdirname(java.lang.String path)Deprecated.usePaths.get(path).getParent().getName()static java.lang.Stringextension(java.lang.String path)Deprecated.useorg.apache.commons.io.FilenameUtils.getExtensionstatic voidfileAppend(java.lang.String fileName, java.lang.String data)Deprecated.usejava.nio.file.Files.write(filename, data.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE)static voidfileAppend(java.lang.String fileName, java.lang.String encoding, java.lang.String data)Deprecated.usejava.nio.file.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)static voidfileDelete(java.lang.String fileName)Deprecated.useFiles.delete(Paths.get(fileName))static booleanfileExists(java.lang.String fileName)Deprecated.usejava.io.File.exists()static java.lang.Stringfilename(java.lang.String path)Deprecated.usePaths.get(path).getName()static java.lang.StringfileRead(java.io.File file)Deprecated.usenew String(java.nio.file.Files.readAllBytes(file.toPath()))static java.lang.StringfileRead(java.io.File file, java.lang.String encoding)Deprecated.usenew String(java.nio.file.Files.readAllBytes(file.toPath()), encoding)static java.lang.StringfileRead(java.lang.String file)Deprecated.usenew String(java.nio.file.Files.readAllBytes(file))static java.lang.String[]fileReadArray(java.io.File file)Deprecated.usejava.nio.file.Files.readAllLines()static voidfileWrite(java.io.File file, java.lang.String encoding, java.lang.String data)Deprecated.usejava.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)static voidfileWrite(java.lang.String fileName, java.lang.String data)Deprecated.usejava.nio.file.Files.write(filename, data.getBytes(), StandardOpenOption.CREATE)static voidfileWrite(java.lang.String fileName, java.lang.String encoding, java.lang.String data)Deprecated.usejava.nio.file.Files.write(Paths.get(filename), data.getBytes(encoding), StandardOpenOption.CREATE)static voidfileWriteArray(java.io.File file, java.lang.String... data)Deprecated.usejava.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)static voidfileWriteArray(java.io.File file, java.lang.String encoding, java.lang.String... data)Deprecated.usejava.nio.file.Files.write(file.toPath(), data.getBytes(encoding), StandardOpenOption.CREATE)static voidforceDelete(java.io.File file)Deprecated.useorg.apache.commons.io.FileUtils.deleteQuietly()static voidforceDelete(java.lang.String file)Deprecated.useorg.apache.commons.io.FileUtils.deleteQuietly()static voidforceMkdir(java.io.File file)Deprecated.useorg.apache.commons.io.FileUtils.forceMkdir()static java.lang.String[]getDefaultExcludes()static java.util.List<java.lang.String>getDefaultExcludesAsList()static java.lang.StringgetDefaultExcludesAsString()static java.util.List<java.lang.String>getDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir)Return the paths to the subdirectories in a directory, relative to the base directory.static java.util.List<java.lang.String>getDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive)Return the paths to the subdirectories in a directory, relative to the base directory.static java.lang.StringgetExtension(java.lang.String filename)Deprecated.useorg.apache.commons.io.FilenameUtils.getExtension()static java.util.List<java.lang.String>getFileAndDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.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 java.util.List<java.lang.String>getFileNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir)Return a list of the files inside a base directory as relative paths from the base.static java.util.List<java.io.File>getFiles(java.io.File directory, java.lang.String includes, java.lang.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 java.util.List<java.io.File>getFiles(java.io.File directory, java.lang.String includes, java.lang.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 java.lang.String[]getFilesFromExtension(java.lang.String directory, java.lang.String... extensions)Given a directory and an array of extensions return an array of compliant files.static booleanisSymbolicLink(java.io.File file)Deprecated.usejava.nio.file.Files.isSymbolicLink(file.toPath())static booleanisSymbolicLinkForSure(java.io.File file)Deprecated.usejava.nio.file.Files.isSymbolicLink(file.toPath())static java.util.List<java.lang.String>loadFile(java.io.File file)Deprecated.assumes the platform default character setstatic voidmkdir(java.lang.String dir)Deprecated.usejava.nio.file.Files.createDirectories(Paths.get(dir))static java.lang.Stringnormalize(java.lang.String path)Deprecated.useorg.apache.commons.io.FilenameUtils.normalize()static java.lang.StringremoveExtension(java.lang.String filename)Deprecated.useorg.apache.commons.io.FilenameUtils.removeExtension()static voidrename(java.io.File from, java.io.File to)Deprecated.usejava.nio.file.Files.move()static java.io.FileresolveFile(java.io.File baseFile, java.lang.String filename)Resolve a filefilenameto its canonical form.static longsizeOfDirectory(java.io.File directory)Deprecated.useorg.apache.commons.io.FileUtils.sizeOf()static longsizeOfDirectory(java.lang.String directory)Deprecated.useorg.apache.commons.io.FileUtils.sizeOf()static java.io.FiletoFile(java.net.URL url)Convert from aURLto aFile.static java.net.URL[]toURLs(java.io.File... files)Convert the array of Files into a list of URLs.
-
-
-
Method Detail
-
getDefaultExcludes
public static java.lang.String[] getDefaultExcludes()
- Returns:
- the default excludes pattern
- See Also:
DirectoryScanner.DEFAULTEXCLUDES
-
getDefaultExcludesAsList
public static java.util.List<java.lang.String> getDefaultExcludesAsList()
- Returns:
- the default excludes pattern as list
- See Also:
getDefaultExcludes()
-
getDefaultExcludesAsString
public static java.lang.String getDefaultExcludesAsString()
- Returns:
- the default excludes pattern as comma separated string
- See Also:
DirectoryScanner.DEFAULTEXCLUDES,StringUtils.join(Object[], String)
-
dirname
@Deprecated public static java.lang.String dirname(java.lang.String path)
Deprecated.usePaths.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 java.lang.String filename(java.lang.String path)
Deprecated.usePaths.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 java.lang.String extension(java.lang.String path)
Deprecated.useorg.apache.commons.io.FilenameUtils.getExtensionReturns 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(java.lang.String fileName)
Deprecated.usejava.io.File.exists()Check if a file exists.- Parameters:
fileName- the file path- Returns:
- true if file exists
-
fileRead
@Deprecated public static java.lang.String fileRead(java.lang.String file) throws java.io.IOExceptionDeprecated.usenew 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:
java.io.IOException- if any
-
fileRead
@Deprecated public static java.lang.String fileRead(java.io.File file) throws java.io.IOExceptionDeprecated.usenew 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:
java.io.IOException- if any
-
fileRead
@Deprecated public static java.lang.String fileRead(java.io.File file, java.lang.String encoding) throws java.io.IOExceptionDeprecated.usenew String(java.nio.file.Files.readAllBytes(file.toPath()), encoding)- Parameters:
file- the file pathencoding- the wanted encoding- Returns:
- the file content using the specified encoding
- Throws:
java.io.IOException- if any
-
fileReadArray
@Deprecated public static java.lang.String[] fileReadArray(java.io.File file) throws java.io.IOExceptionDeprecated.usejava.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:
java.io.IOException- in case of failure
-
fileAppend
@Deprecated public static void fileAppend(java.lang.String fileName, java.lang.String data) throws java.io.IOExceptionDeprecated.usejava.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 writedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileAppend
@Deprecated public static void fileAppend(java.lang.String fileName, java.lang.String encoding, java.lang.String data) throws java.io.IOExceptionDeprecated.usejava.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 writeencoding- the encoding of the filedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileWrite
@Deprecated public static void fileWrite(java.lang.String fileName, java.lang.String data) throws java.io.IOExceptionDeprecated.usejava.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 writedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileWrite
@Deprecated public static void fileWrite(java.lang.String fileName, java.lang.String encoding, java.lang.String data) throws java.io.IOExceptionDeprecated.usejava.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 writeencoding- the encoding of the filedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileWrite
@Deprecated public static void fileWrite(java.io.File file, java.lang.String encoding, java.lang.String data) throws java.io.IOExceptionDeprecated.usejava.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 writeencoding- the encoding of the filedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileWriteArray
@Deprecated public static void fileWriteArray(java.io.File file, java.lang.String... data) throws java.io.IOExceptionDeprecated.usejava.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 writedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileWriteArray
@Deprecated public static void fileWriteArray(java.io.File file, java.lang.String encoding, java.lang.String... data) throws java.io.IOExceptionDeprecated.usejava.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 writeencoding- the encoding of the filedata- the content to write to the file- Throws:
java.io.IOException- if any
-
fileDelete
@Deprecated public static void fileDelete(java.lang.String fileName)
Deprecated.useFiles.delete(Paths.get(fileName))Deletes a file.- Parameters:
fileName- the path of the file to delete
-
getFilesFromExtension
public static java.lang.String[] getFilesFromExtension(java.lang.String directory, java.lang.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 directoryextensions- an array of expected extensions- Returns:
- an array of files for the wanted extensions
-
mkdir
@Deprecated public static void mkdir(java.lang.String dir)
Deprecated.usejava.nio.file.Files.createDirectories(Paths.get(dir))Simple way to make a directory.- Parameters:
dir- the directory to create- Throws:
java.lang.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(java.io.File file1, java.io.File file2) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.contentEquals()Compare the contents of two files to determine if they are equal or not.- Parameters:
file1- the first filefile2- the second file- Returns:
- true if the content of the files are equal or they both don't exist, false otherwise
- Throws:
java.io.IOException- if any
-
toFile
public static java.io.File toFile(java.net.URL url)
Convert from aURLto aFile.- Parameters:
url- file URL- Returns:
- the equivalent
Fileobject, ornullif the URL's protocol is notfile
-
toURLs
public static java.net.URL[] toURLs(java.io.File... files) throws java.io.IOExceptionConvert the array of Files into a list of URLs.- Parameters:
files- the array of files- Returns:
- the array of URLs
- Throws:
java.io.IOException- if an error occurs
-
removeExtension
@Deprecated public static java.lang.String removeExtension(java.lang.String filename)
Deprecated.useorg.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 java.lang.String getExtension(java.lang.String filename)
Deprecated.useorg.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(java.io.File source, java.io.File destinationDirectory) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.copyFileToDirectory()Copy file from source to destination. IfdestinationDirectorydoes not exist, it (and any parent directories) will be created. If a filesourceindestinationDirectoryexists, it will be overwritten.- Parameters:
source- an existingFileto copydestinationDirectory- a directory to copysourceinto- Throws:
java.lang.IllegalArgumentException- ifdestinationDirectoryisn't a directoryjava.io.IOException- ifsourcedoes not exist, the file indestinationDirectorycannot be written to, or an IO error occurs during copyingjava.io.FileNotFoundException- ifsourceisn't a normal file
-
copyFile
@Deprecated public static void copyFile(java.io.File source, java.io.File destination) throws java.io.IOExceptionDeprecated.usejava.nio.file.Files.copy(source.toPath(), destination.toPath(), LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING)Copy file from source to destination. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
source- an existing non-directoryFileto copy bytes fromdestination- a non-directoryFileto write bytes to (possibly overwriting)- Throws:
java.io.IOException- ifsourcedoes not exist,destinationcannot be written to, or an IO error occurs during copyingjava.io.FileNotFoundException- ifdestinationis a directory
-
copyURLToFile
public static void copyURLToFile(java.net.URL source, java.io.File destination) throws java.io.IOExceptionDeprecated.usejava.nio.file.Files.copy(source.openStream(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)Copies bytes from the URLsourceto a filedestination. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
source- aURLto copy bytes fromdestination- a non-directoryFileto write bytes to (possibly overwriting)- Throws:
java.io.IOException- ifsourceURL cannot be openeddestinationcannot be written to- an IO error occurs during copying
-
normalize
@Deprecated public static java.lang.String normalize(java.lang.String path)
Deprecated.useorg.apache.commons.io.FilenameUtils.normalize()Normalize a path. Eliminates "/../" and "/./" in a string. Returnsnullif 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
nullif too many ..'s
-
resolveFile
public static java.io.File resolveFile(java.io.File baseFile, java.lang.String filename)Resolve a filefilenameto its canonical form. Iffilenameis relative (doesn't start with/), it is resolved relative tobaseFile. Otherwise it is treated as a normal root-relative path.- Parameters:
baseFile- where to resolvefilenamefrom, iffilenameis relativefilename- absolute or relative file path to resolve- Returns:
- the canonical
Fileoffilename
-
forceDelete
@Deprecated public static void forceDelete(java.lang.String file) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.deleteQuietly()Delete a file. If file is directory, delete it and all sub-directories.- Parameters:
file- the file path- Throws:
java.io.IOException- if any
-
forceDelete
@Deprecated public static void forceDelete(java.io.File file) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.deleteQuietly()Delete a file. If file is directory, delete it and all sub-directories.- Parameters:
file- a file- Throws:
java.io.IOException- if any
-
delete
@Deprecated public static void delete(java.io.File file) throws java.io.IOExceptionDeprecated.usejava.nio.file.Files.delete(file.toPath())Deletes a file.- Parameters:
file- the file to delete- Throws:
java.io.IOException- if the file cannot be deleted
-
deleteLegacyStyle
@Deprecated public static boolean deleteLegacyStyle(java.io.File file)
Deprecated.usejava.nio.file.Files.delete(file.toPath())- Parameters:
file- the file- Returns:
- true / false
-
forceMkdir
@Deprecated public static void forceMkdir(java.io.File file) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.forceMkdir()Make a directory.- Parameters:
file- not null- Throws:
java.lang.IllegalArgumentException- if the file contains illegal Windows characters under Windows OSjava.io.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(java.lang.String directory) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.deleteDirectory()Recursively delete a directory.- Parameters:
directory- a directory- Throws:
java.io.IOException- if any
-
deleteDirectory
@Deprecated public static void deleteDirectory(java.io.File directory) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.deleteDirectory()Recursively delete a directory.- Parameters:
directory- a directory- Throws:
java.io.IOException- if any
-
cleanDirectory
@Deprecated public static void cleanDirectory(java.io.File directory) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.cleanDirectory()Remove all files from a directory without deleting it.- Parameters:
directory- a directory- Throws:
java.io.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(java.lang.String directory)
Deprecated.useorg.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(java.io.File directory)
Deprecated.useorg.apache.commons.io.FileUtils.sizeOf()Recursively count size of a directory.- Parameters:
directory- a directory- Returns:
- size of directory in bytes
-
getFiles
public static java.util.List<java.io.File> getFiles(java.io.File directory, java.lang.String includes, java.lang.String excludes) throws java.io.IOExceptionReturn 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 scanincludes- the Ant includes pattern, comma separatedexcludes- the Ant excludes pattern, comma separated- Returns:
- a list of File objects
- Throws:
java.io.IOException- never- See Also:
getFileNames(File, String, String, boolean)
-
getFiles
public static java.util.List<java.io.File> getFiles(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir) throws java.io.IOExceptionReturn 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 scanincludes- the includes pattern, comma separatedexcludes- the excludes pattern, comma separatedincludeBasedir- true to include the base dir in each file- Returns:
- a list of File objects
- Throws:
java.io.IOException- never- See Also:
getFileNames(File, String, String, boolean)
-
getFileNames
public static java.util.List<java.lang.String> getFileNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir) throws java.io.IOExceptionReturn 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 scanincludes- the Ant includes pattern, comma separatedexcludes- the Ant excludes pattern, comma separatedincludeBasedir- true to include the base directory in each String of file- Returns:
- a list of file names
- Throws:
java.io.IOException- never
-
getDirectoryNames
public static java.util.List<java.lang.String> getDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir) throws java.io.IOExceptionReturn 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 searchincludes- the Ant includes pattern, comma separatedexcludes- the Ant excludes pattern, comma separatedincludeBasedir- true to include the base directory at the start of each path- Returns:
- a list of relative paths of directories
- Throws:
java.io.IOException- never
-
getDirectoryNames
public static java.util.List<java.lang.String> getDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive) throws java.io.IOExceptionReturn 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 searchincludes- the Ant includes pattern, comma separatedexcludes- the Ant excludes pattern, comma separatedincludeBasedir- true to include the base directory at the start of each pathisCaseSensitive- true if the includes and excludes are case sensitive- Returns:
- a list of relative paths of directories
- Throws:
java.io.IOException- never
-
getFileAndDirectoryNames
public static java.util.List<java.lang.String> getFileAndDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.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 scanincludes- the Ant includes pattern, comma separatedexcludes- the Ant excludes pattern, comma separatedincludeBasedir- true to include the base directory at the start of each pathisCaseSensitive- true if the includes and excludes are case sensitivegetFiles- true to include regular files in the listgetDirectories- true to include directories in the list- Returns:
- a list of relative paths
-
copyDirectory
@Deprecated public static void copyDirectory(java.io.File sourceDirectory, java.io.File destinationDirectory) throws java.io.IOExceptionDeprecated.useorg.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:
java.io.IOException- if any
-
copyDirectory
@Deprecated public static void copyDirectory(java.io.File sourceDirectory, java.io.File destinationDirectory, java.lang.String includes, java.lang.String excludes) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.copyDirectory()Copy the contents of a directory into another one.- Parameters:
sourceDirectory- the source directorydestinationDirectory- the target directoryincludes- ant include patternexcludes- ant exclude pattern- Throws:
java.io.IOException- if the source is a file or cannot be copied- See Also:
getFiles(File, String, String)
-
copyDirectoryStructure
@Deprecated public static void copyDirectoryStructure(java.io.File sourceDirectory, java.io.File destinationDirectory) throws java.io.IOExceptionDeprecated.useorg.apache.commons.io.FileUtils.copyDirectory()Copies an entire directory structure.Note:
- It will include empty directories.
- The
sourceDirectorymust exist.
- Parameters:
sourceDirectory- the existing directory to be copieddestinationDirectory- the new directory to be created- Throws:
java.io.IOException- if any
-
rename
@Deprecated public static void rename(java.io.File from, java.io.File to) throws java.io.IOExceptionDeprecated.usejava.nio.file.Files.move()Renames a file, even if that involves crossing file system boundaries.This will remove
to(if it exists), ensure thatto's parent directory exists and movefrom, which involves deletingfromas well.- Parameters:
from- the file to moveto- the new file name- Throws:
java.io.IOException- if anything bad happens during this process. Note thattomay have been deleted already when this happens.
-
createTempFile
@Deprecated public static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File parentDir)Deprecated.usejava.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 numbersuffix- file extension; include the '.'parentDir- directory to create the temporary file in-java.io.tmpdirused if not specified- Returns:
- a File reference to the new temporary file
-
copyFile
@Deprecated public static void copyFile(java.io.File from, java.io.File to, java.lang.String encoding, FileUtils.FilterWrapper... wrappers) throws java.io.IOExceptionDeprecated.useorg.apache.maven.shared.filtering.FilteringUtils.copyFile()insteadIf wrappers is null or empty, the file will be copied only if to.lastModified() < from.lastModified()- Parameters:
from- the file to copyto- the destination fileencoding- the file output encoding (only if wrappers is not empty)wrappers- array ofFileUtils.FilterWrapper- Throws:
java.io.IOException- if an IO error occurs during copying or filtering
-
copyFile
@Deprecated public static void copyFile(java.io.File from, java.io.File to, java.lang.String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite) throws java.io.IOExceptionDeprecated.useorg.apache.maven.shared.filtering.FilteringUtils.copyFile()insteadIf 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 copyto- the destination fileencoding- the file output encoding (only if wrappers is not empty)wrappers- array ofFileUtils.FilterWrapperoverwrite- if true and wrappers is null or empty, the file will be copied even if to.lastModified() < from.lastModified()- Throws:
java.io.IOException- if an IO error occurs during copying or filtering
-
loadFile
@Deprecated public static java.util.List<java.lang.String> loadFile(java.io.File file) throws java.io.IOExceptionDeprecated.assumes the platform default character setNote: 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:
java.io.IOException- if any
-
isSymbolicLink
@Deprecated public static boolean isSymbolicLink(java.io.File file) throws java.io.IOExceptionDeprecated.usejava.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:
java.io.IOException- in case of failure
-
isSymbolicLinkForSure
@Deprecated public static boolean isSymbolicLinkForSure(java.io.File file) throws java.io.IOExceptionDeprecated.usejava.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:
java.io.IOException- in case of failure
-
createSymbolicLink
public static java.io.File createSymbolicLink(java.io.File symlink, java.io.File target) throws java.io.IOExceptionCreate a new symbolic link, possibly replacing an existing symbolic link.- Parameters:
symlink- the link nametarget- the target- Returns:
- the linked file
- Throws:
java.io.IOException- in case of an error- See Also:
which creates a new symbolic link but does not replace existing symbolic links
-
-