public class FileUtils
extends java.lang.Object
/www/hosted/mysite/index.html
, can be broken into:
/www/hosted/mysite/index
-- retrievable through removeExtension(java.lang.String)
html
-- retrievable through getExtension(java.lang.String)
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.
Modifier and Type | Class and Description |
---|---|
static class |
FileUtils.FilterWrapper
Wrapper class for Filter.
|
Modifier and Type | Field and Description |
---|---|
private static int |
FILE_COPY_BUFFER_SIZE
The file copy buffer size (30 MB)
|
private static java.lang.String |
FS
The vm line separator
|
private static java.lang.String[] |
INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
Non-valid Characters for naming files, folders under Windows:
":", "*", "?", "\"", "<", ">", "|" |
private static int |
ONE_KB
The number of bytes in a kilobyte.
|
private static int |
ONE_MB
The number of bytes in a megabyte.
|
Modifier | Constructor and Description |
---|---|
protected |
FileUtils()
protected constructor.
|
Modifier and Type | Method and Description |
---|---|
private static java.util.List<java.lang.String> |
blendFilesToList(java.util.List<java.lang.String> v,
java.lang.String... files)
Private helper method for getFilesFromExtension()
|
private static java.nio.charset.Charset |
charset(java.lang.String encoding)
Returns the named charset or the default charset.
|
static void |
cleanDirectory(java.io.File directory)
Deprecated.
use
org.apache.commons.io.FileUtils.cleanDirectory() |
static boolean |
contentEquals(java.io.File file1,
java.io.File file2)
Compare the contents of two files to determine if they are equal or not.
|
static void |
copyDirectory(java.io.File sourceDirectory,
java.io.File destinationDirectory)
Deprecated.
use
org.apache.commons.io.FileUtils.copyDirectory() |
static void |
copyDirectory(java.io.File sourceDirectory,
java.io.File destinationDirectory,
java.lang.String includes,
java.lang.String excludes)
Deprecated.
use
org.apache.commons.io.FileUtils.copyDirectory() |
static void |
copyDirectoryStructure(java.io.File sourceDirectory,
java.io.File destinationDirectory)
Deprecated.
use
org.apache.commons.io.FileUtils.copyDirectory() |
private static void |
copyDirectoryStructure(java.io.File sourceDirectory,
java.io.File destinationDirectory,
java.io.File rootDestinationDirectory,
boolean onlyModifiedFiles) |
static void |
copyFile(java.io.File source,
java.io.File destination)
Deprecated.
use
java.nio.Files.copy(source.toPath(), destination.toPath(), LinkOption.NOFOLLOW_LINKS,
StandardCopyOption.REPLACE_EXISTING) |
static void |
copyFile(java.io.File from,
java.io.File to,
java.lang.String encoding,
FileUtils.FilterWrapper... wrappers)
If wrappers is null or empty, the file will be copied only if to.lastModified() < from.lastModified()
|
static void |
copyFile(java.io.File from,
java.io.File to,
java.lang.String encoding,
FileUtils.FilterWrapper[] wrappers,
boolean overwrite)
If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if
overwrite is true
|
private static boolean |
copyFileIfModified(java.io.File source,
java.io.File destination)
Copy file from source to destination only if source timestamp is later than the destination timestamp.
|
private static void |
copyFilePermissions(java.io.File source,
java.io.File destination)
Attempts to copy file permissions from the source to the destination file.
|
static void |
copyFileToDirectory(java.io.File source,
java.io.File destinationDirectory)
Deprecated.
use
org.apache.commons.io.FileUtils.copyFileToDirectory() |
private static void |
copyFileToDirectoryIfModified(java.io.File source,
java.io.File destinationDirectory)
Copy file from source to destination only if source is newer than the target file.
|
private static void |
copyStreamToFile(java.io.InputStream source,
java.io.File destination)
Deprecated.
use
java.nio.Files.copy(source, destination.toPath(),
StandardCopyOption.REPLACE_EXISTING) |
static void |
copyURLToFile(java.net.URL source,
java.io.File destination)
Deprecated.
use
java.nio.Files.copy(source.openStream(), destination.toPath(),
StandardCopyOption.REPLACE_EXISTING) |
static java.io.File |
createSymbolicLink(java.io.File symlink,
java.io.File target)
Create a new symbolic link, possibly replacing an existing symbolic link.
|
static java.io.File |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
java.io.File parentDir)
Deprecated.
use
java.nio.Files.createTempFile() |
static void |
delete(java.io.File file)
Deprecated.
use
java.nio.files.Files.delete(file.toPath()) |
static void |
deleteDirectory(java.io.File directory)
Deprecated.
use
org.apache.commons.io.FileUtils.deleteDirectory() |
static void |
deleteDirectory(java.lang.String directory)
Deprecated.
use
org.apache.commons.io.FileUtils.deleteDirectory() |
private static boolean |
deleteFile(java.io.File file)
Accommodate Windows bug encountered in both Sun and IBM JDKs.
|
static boolean |
deleteLegacyStyle(java.io.File file)
Deprecated.
use
java.nio.files.Files.delete(file.toPath()) |
static java.lang.String |
dirname(java.lang.String path)
Deprecated.
use
Paths.get(path).getParent().getName() |
private static void |
doCopyFile(java.io.File source,
java.io.File destination) |
static java.lang.String |
extension(java.lang.String path)
Deprecated.
use
org.apache.commons.io.FilenameUtils.getExtension |
static void |
fileAppend(java.lang.String fileName,
java.lang.String data)
Deprecated.
use
java.nio.files.Files.write(filename, data.getBytes(),
StandardOpenOption.APPEND, StandardOpenOption.CREATE) |
static void |
fileAppend(java.lang.String fileName,
java.lang.String encoding,
java.lang.String data)
Deprecated.
use
java.nio.files.Files.write(filename, data.getBytes(encoding),
StandardOpenOption.APPEND, StandardOpenOption.CREATE) |
static void |
fileDelete(java.lang.String fileName)
Deprecated.
use
Files.delete(Paths.get(fileName)) |
static boolean |
fileExists(java.lang.String fileName)
Deprecated.
use
java.io.File.exists() |
static java.lang.String |
filename(java.lang.String path)
Deprecated.
use
Paths.get(path).getName() |
static java.lang.String |
fileRead(java.io.File file)
Deprecated.
use
new String(java.nio.files.Files.readAllBytes(file.toPath())) |
static java.lang.String |
fileRead(java.io.File file,
java.lang.String encoding)
Deprecated.
use
new String(java.nio.files.Files.readAllBytes(file.toPath()), encoding) |
static java.lang.String |
fileRead(java.lang.String file)
Deprecated.
use
new String(java.nio.files.Files.readAllBytes(file)) |
private static java.lang.String |
fileRead(java.lang.String file,
java.lang.String encoding)
Deprecated.
use
new String(java.nio.files.Files.readAllBytes(Paths.get(file)), encoding) |
static java.lang.String[] |
fileReadArray(java.io.File file)
Deprecated.
use
java.nio.files.Files.readAllLines() |
static void |
fileWrite(java.io.File file,
java.lang.String encoding,
java.lang.String data)
Deprecated.
use
java.nio.files.Files.write(file.toPath(),
data.getBytes(encoding), StandardOpenOption.CREATE) |
static void |
fileWrite(java.lang.String fileName,
java.lang.String data)
Deprecated.
use
java.nio.files.Files.write(filename,
data.getBytes(), StandardOpenOption.CREATE) |
static void |
fileWrite(java.lang.String fileName,
java.lang.String encoding,
java.lang.String data)
Deprecated.
use
java.nio.files.Files.write(Paths.get(filename),
data.getBytes(encoding), StandardOpenOption.CREATE) |
static void |
fileWriteArray(java.io.File file,
java.lang.String... data)
Deprecated.
use
java.nio.files.Files.write(file.toPath(),
data.getBytes(encoding), StandardOpenOption.CREATE) |
static void |
fileWriteArray(java.io.File file,
java.lang.String encoding,
java.lang.String... data)
Deprecated.
use
java.nio.files.Files.write(file.toPath(),
data.getBytes(encoding), StandardOpenOption.CREATE) |
static void |
forceDelete(java.io.File file)
Deprecated.
use
org.apache.commons.io.FileUtils.deleteQuietly() |
static void |
forceDelete(java.lang.String file)
Deprecated.
use
org.apache.commons.io.FileUtils.deleteQuietly() |
static void |
forceMkdir(java.io.File file)
Make a directory.
|
static java.lang.String[] |
getDefaultExcludes() |
static java.util.List<java.lang.String> |
getDefaultExcludesAsList() |
static java.lang.String |
getDefaultExcludesAsString() |
static java.util.List<java.lang.String> |
getDirectoryNames(java.io.File directory,
java.lang.String includes,
java.lang.String excludes,
boolean includeBasedir)
Return a list of directories as String depending options.
|
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 a list of directories as Strings.
|
static java.lang.String |
getExtension(java.lang.String filename)
Deprecated.
use
org.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 a list of file names as Strings.
|
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 files as String depending options.
|
private static java.util.List<java.lang.String> |
getFileNames(java.io.File directory,
java.lang.String includes,
java.lang.String excludes,
boolean includeBasedir,
boolean isCaseSensitive)
Return a list of files as String depending options.
|
static java.util.List<java.io.File> |
getFiles(java.io.File directory,
java.lang.String includes,
java.lang.String excludes)
Return the files contained in the directory, 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 the files contained in the directory, 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 boolean |
isSymbolicLink(java.io.File file)
Deprecated.
use
java.nio.file.Files.isSymbolicLink(file.toPath()) |
static boolean |
isSymbolicLinkForSure(java.io.File file)
Deprecated.
use
java.nio.file.Files.isSymbolicLink(file.toPath()) |
private static boolean |
isValidFile(java.lang.String file,
java.lang.String... extensions)
Checks to see if a file is of a particular type(s).
|
private static boolean |
isValidWindowsFileName(java.io.File f)
For Windows OS, check if the file name contains any of the following characters:
":", "*", "?", "\"", "<", ">", "|" |
static java.util.List<java.lang.String> |
loadFile(java.io.File file)
Deprecated.
assumes the platform default character set
|
static void |
mkdir(java.lang.String dir)
Deprecated.
use
java.nio.file.Files.createDirectories(Paths.get(dir)) |
private static void |
mkdirsFor(java.io.File destination) |
static java.lang.String |
normalize(java.lang.String path)
Deprecated.
use
org.apache.commons.io.FileNameUtils.normalize() |
private static int |
positiveRandom(java.util.Random rand) |
static java.lang.String |
removeExtension(java.lang.String filename)
Deprecated.
use
org.apache.commons.io.FilenameUtils.removeExtension() |
static void |
rename(java.io.File from,
java.io.File to)
Deprecated.
use
java.nio.Files.move() |
static java.io.File |
resolveFile(java.io.File baseFile,
java.lang.String filename)
Resolve a file
filename to its canonical form. |
static long |
sizeOfDirectory(java.io.File directory)
Deprecated.
use
org.apache.commons.io.FileUtils.sizeOf() |
static long |
sizeOfDirectory(java.lang.String directory)
Deprecated.
use
org.apache.commons.io.FileUtils.sizeOf() |
static java.io.File |
toFile(java.net.URL url)
Convert from a
URL to a File . |
static java.net.URL[] |
toURLs(java.io.File... files)
Convert the array of Files into a list of URLs.
|
private static final int ONE_KB
private static final int ONE_MB
private static final int FILE_COPY_BUFFER_SIZE
private static final java.lang.String FS
private static final java.lang.String[] INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
":", "*", "?", "\"", "<", ">", "|"
@Nonnull public static java.lang.String[] getDefaultExcludes()
DirectoryScanner.DEFAULTEXCLUDES
@Nonnull public static java.util.List<java.lang.String> getDefaultExcludesAsList()
getDefaultExcludes()
@Nonnull public static java.lang.String getDefaultExcludesAsString()
DirectoryScanner.DEFAULTEXCLUDES
,
StringUtils.join(Object[], String)
@Deprecated @Nonnull public static java.lang.String dirname(@Nonnull java.lang.String path)
Paths.get(path).getParent().getName()
path
- the file path@Deprecated @Nonnull public static java.lang.String filename(@Nonnull java.lang.String path)
Paths.get(path).getName()
path
- the file path@Deprecated @Nonnull public static java.lang.String extension(@Nonnull java.lang.String path)
org.apache.commons.io.FilenameUtils.getExtension
path
- the file path@Deprecated public static boolean fileExists(@Nonnull java.lang.String fileName)
java.io.File.exists()
fileName
- the file path@Deprecated @Nonnull public static java.lang.String fileRead(@Nonnull java.lang.String file) throws java.io.IOException
new String(java.nio.files.Files.readAllBytes(file))
file
- the file pathjava.io.IOException
- if any@Deprecated @Nonnull private static java.lang.String fileRead(@Nonnull java.lang.String file, @Nullable java.lang.String encoding) throws java.io.IOException
new String(java.nio.files.Files.readAllBytes(Paths.get(file)), encoding)
file
- the file pathencoding
- the wanted encodingjava.io.IOException
- if any@Deprecated @Nonnull public static java.lang.String fileRead(@Nonnull java.io.File file) throws java.io.IOException
new String(java.nio.files.Files.readAllBytes(file.toPath()))
file
- the file pathjava.io.IOException
- if any@Deprecated @Nonnull public static java.lang.String fileRead(@Nonnull java.io.File file, @Nullable java.lang.String encoding) throws java.io.IOException
new String(java.nio.files.Files.readAllBytes(file.toPath()), encoding)
file
- the file pathencoding
- the wanted encodingjava.io.IOException
- if any@Deprecated @Nonnull public static java.lang.String[] fileReadArray(@Nonnull java.io.File file) throws java.io.IOException
java.nio.files.Files.readAllLines()
file
- the file pathjava.io.IOException
- in case of failure@Deprecated public static void fileAppend(@Nonnull java.lang.String fileName, @Nonnull java.lang.String data) throws java.io.IOException
java.nio.files.Files.write(filename, data.getBytes(),
StandardOpenOption.APPEND, StandardOpenOption.CREATE)
fileName
- the path of the file to writedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileAppend(@Nonnull java.lang.String fileName, @Nullable java.lang.String encoding, @Nonnull java.lang.String data) throws java.io.IOException
java.nio.files.Files.write(filename, data.getBytes(encoding),
StandardOpenOption.APPEND, StandardOpenOption.CREATE)
fileName
- the path of the file to writeencoding
- the encoding of the filedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileWrite(@Nonnull java.lang.String fileName, @Nonnull java.lang.String data) throws java.io.IOException
java.nio.files.Files.write(filename,
data.getBytes(), StandardOpenOption.CREATE)
fileName
- the path of the file to writedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileWrite(@Nonnull java.lang.String fileName, @Nullable java.lang.String encoding, @Nonnull java.lang.String data) throws java.io.IOException
java.nio.files.Files.write(Paths.get(filename),
data.getBytes(encoding), StandardOpenOption.CREATE)
fileName
- the path of the file to writeencoding
- the encoding of the filedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileWrite(@Nonnull java.io.File file, @Nullable java.lang.String encoding, @Nonnull java.lang.String data) throws java.io.IOException
java.nio.files.Files.write(file.toPath(),
data.getBytes(encoding), StandardOpenOption.CREATE)
file
- the path of the file to writeencoding
- the encoding of the filedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileWriteArray(@Nonnull java.io.File file, @Nullable java.lang.String... data) throws java.io.IOException
java.nio.files.Files.write(file.toPath(),
data.getBytes(encoding), StandardOpenOption.CREATE)
file
- the path of the file to writedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileWriteArray(@Nonnull java.io.File file, @Nullable java.lang.String encoding, @Nullable java.lang.String... data) throws java.io.IOException
java.nio.files.Files.write(file.toPath(),
data.getBytes(encoding), StandardOpenOption.CREATE)
file
- the path of the file to writeencoding
- the encoding of the filedata
- the content to write to the filejava.io.IOException
- if any@Deprecated public static void fileDelete(@Nonnull java.lang.String fileName)
Files.delete(Paths.get(fileName))
fileName
- the path of the file to deletepublic static java.lang.String[] getFilesFromExtension(@Nonnull java.lang.String directory, @Nonnull java.lang.String... extensions)
The given extensions should be like "java" and not like ".java".
directory
- the path of the directoryextensions
- an array of expected extensions@Nonnull private static java.util.List<java.lang.String> blendFilesToList(@Nonnull java.util.List<java.lang.String> v, @Nonnull java.lang.String... files)
private static boolean isValidFile(@Nonnull java.lang.String file, @Nonnull java.lang.String... extensions)
@Deprecated public static void mkdir(@Nonnull java.lang.String dir)
java.nio.file.Files.createDirectories(Paths.get(dir))
dir
- the directory to createjava.lang.IllegalArgumentException
- if the dir contains illegal Windows characters under Windows OSINVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
public static boolean contentEquals(@Nonnull java.io.File file1, @Nonnull java.io.File file2) throws java.io.IOException
file1
- the first filefile2
- the second filejava.io.IOException
- if any@Nullable public static java.io.File toFile(@Nullable java.net.URL url)
URL
to a File
.url
- file URLFile
object, or null
if the URL's protocol
is not file
@Nonnull public static java.net.URL[] toURLs(@Nonnull java.io.File... files) throws java.io.IOException
files
- the array of filesjava.io.IOException
- if an error occurs@Deprecated @Nonnull public static java.lang.String removeExtension(@Nonnull java.lang.String filename)
org.apache.commons.io.FilenameUtils.removeExtension()
foo.txt → foo a\b\c.jpg → a\b\c a\b\c → a\b\c
filename
- the path of the file@Deprecated @Nonnull public static java.lang.String getExtension(@Nonnull java.lang.String filename)
org.apache.commons.io.FilenameUtils.getExtension()
foo.txt → "txt" a\b\c.jpg → "jpg" a\b\c → ""
filename
- the path of the file@Deprecated public static void copyFileToDirectory(@Nonnull java.io.File source, @Nonnull java.io.File destinationDirectory) throws java.io.IOException
org.apache.commons.io.FileUtils.copyFileToDirectory()
destinationDirectory
does not exist, it
(and any parent directories) will be created. If a file source
in
destinationDirectory
exists, it will be overwritten.source
- an existing File
to copydestinationDirectory
- a directory to copy source
intojava.io.FileNotFoundException
- if source
isn't a normal filejava.lang.IllegalArgumentException
- if destinationDirectory
isn't a directoryjava.io.IOException
- if source
does not exist, the file in
destinationDirectory
cannot be written to, or an IO error
occurs during copyingprivate static void copyFileToDirectoryIfModified(@Nonnull java.io.File source, @Nonnull java.io.File destinationDirectory) throws java.io.IOException
destinationDirectory
does not exist, it
(and any parent directories) is created. If a file source
in
destinationDirectory
exists, it is overwritten.source
- an existing File
to copydestinationDirectory
- a directory to copy source
intojava.io.FileNotFoundException
- if source
isn't a normal filejava.lang.IllegalArgumentException
- if destinationDirectory
isn't a directoryjava.io.IOException
- if source
does not exist, the file in
destinationDirectory
cannot be written to, or an IO error
occurs during copying@Deprecated public static void copyFile(@Nonnull java.io.File source, @Nonnull java.io.File destination) throws java.io.IOException
java.nio.Files.copy(source.toPath(), destination.toPath(), LinkOption.NOFOLLOW_LINKS,
StandardCopyOption.REPLACE_EXISTING)
destination
will be
created if they don't already exist. destination
will be overwritten if it
already exists.source
- an existing non-directory File
to copy bytes fromdestination
- a non-directory File
to write bytes to (possibly
overwriting)java.io.IOException
- if source
does not exist, destination
cannot be
written to, or an IO error occurs during copyingjava.io.FileNotFoundException
- if destination
is a directoryprivate static void mkdirsFor(@Nonnull java.io.File destination)
private static void doCopyFile(@Nonnull java.io.File source, @Nonnull java.io.File destination) throws java.io.IOException
java.io.IOException
private static boolean copyFileIfModified(@Nonnull java.io.File source, @Nonnull java.io.File destination) throws java.io.IOException
destination
will be created if they don't already exist.
destination
will be overwritten if it already exists.source
- An existing non-directory File
to copy bytes from.destination
- A non-directory File
to write bytes to (possibly
overwriting).java.io.IOException
- if source
does not exist, destination
cannot be
written to, or an IO error occurs during copying.public static void copyURLToFile(@Nonnull java.net.URL source, @Nonnull java.io.File destination) throws java.io.IOException
java.nio.Files.copy(source.openStream(), destination.toPath(),
StandardCopyOption.REPLACE_EXISTING)
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.source
- a URL
to copy bytes fromdestination
- a non-directory File
to write bytes to (possibly
overwriting)java.io.IOException
- if
source
URL cannot be openeddestination
cannot be written to@Deprecated private static void copyStreamToFile(@Nonnull @WillClose java.io.InputStream source, @Nonnull java.io.File destination) throws java.io.IOException
java.nio.Files.copy(source, destination.toPath(),
StandardCopyOption.REPLACE_EXISTING)
InputStream
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.source
- an InputStream
to copy bytes from. This stream is
guaranteed to be closed.destination
- a non-directory File
to write bytes to (possibly
overwriting)java.io.IOException
- if
source
cannot be openeddestination
cannot be written to@Deprecated @Nonnull public static java.lang.String normalize(@Nonnull java.lang.String path)
org.apache.commons.io.FileNameUtils.normalize()
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
path
- the path to normalizenull
if too many ..'s@Nonnull public static java.io.File resolveFile(java.io.File baseFile, @Nonnull java.lang.String filename)
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.baseFile
- where to resolve filename
from, if filename
is relativefilename
- absolute or relative file path to resolveFile
of filename
@Deprecated public static void forceDelete(@Nonnull java.lang.String file) throws java.io.IOException
org.apache.commons.io.FileUtils.deleteQuietly()
file
- the file pathjava.io.IOException
- if any@Deprecated public static void forceDelete(@Nonnull java.io.File file) throws java.io.IOException
org.apache.commons.io.FileUtils.deleteQuietly()
file
- a filejava.io.IOException
- if any@Deprecated public static void delete(@Nonnull java.io.File file) throws java.io.IOException
java.nio.files.Files.delete(file.toPath())
file
- the file to deletejava.io.IOException
- if the file cannot be deleted@Deprecated public static boolean deleteLegacyStyle(@Nonnull java.io.File file)
java.nio.files.Files.delete(file.toPath())
file
- the fileprivate static boolean deleteFile(@Nonnull java.io.File file) throws java.io.IOException
file
- a filejava.io.IOException
- if anypublic static void forceMkdir(@Nonnull java.io.File file) throws java.io.IOException
file
- not nulljava.io.IOException
- if a file already exists with the specified name or the directory is unable to be createdjava.lang.IllegalArgumentException
- if the file contains illegal Windows characters under Windows OS.INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
@Deprecated public static void deleteDirectory(@Nonnull java.lang.String directory) throws java.io.IOException
org.apache.commons.io.FileUtils.deleteDirectory()
directory
- a directoryjava.io.IOException
- if any@Deprecated public static void deleteDirectory(@Nonnull java.io.File directory) throws java.io.IOException
org.apache.commons.io.FileUtils.deleteDirectory()
directory
- a directoryjava.io.IOException
- if any@Deprecated public static void cleanDirectory(@Nonnull java.io.File directory) throws java.io.IOException
org.apache.commons.io.FileUtils.cleanDirectory()
directory
- a directoryjava.io.IOException
- if any. This can leave cleaning in a half-finished state where
some but not all files have been deleted.@Deprecated public static long sizeOfDirectory(@Nonnull java.lang.String directory)
org.apache.commons.io.FileUtils.sizeOf()
directory
- a directory@Deprecated public static long sizeOfDirectory(@Nonnull java.io.File directory)
org.apache.commons.io.FileUtils.sizeOf()
directory
- a directory@Nonnull public static java.util.List<java.io.File> getFiles(@Nonnull java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes) throws java.io.IOException
directory
- the directory to scanincludes
- the Ant includes pattern, comma separatedexcludes
- the Ant excludes pattern, comma separatedjava.io.IOException
- in case of failure.getFileNames(File, String, String, boolean)
@Nonnull public static java.util.List<java.io.File> getFiles(@Nonnull java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes, boolean includeBasedir) throws java.io.IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each filejava.io.IOException
- in case of failure.getFileNames(File, String, String, boolean)
@Nonnull public static java.util.List<java.lang.String> getFileNames(@Nonnull java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes, boolean includeBasedir) throws java.io.IOException
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 filejava.io.IOException
- in case of failure@Nonnull private static java.util.List<java.lang.String> getFileNames(@Nonnull java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive) throws java.io.IOException
directory
- the directory to scanincludes
- the Ant includes pattern, comma separatedexcludes
- the Ant excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of fileisCaseSensitive
- true if case sensitivejava.io.IOException
@Nonnull public static java.util.List<java.lang.String> getDirectoryNames(@Nonnull java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes, boolean includeBasedir) throws java.io.IOException
directory
- the directory to scanincludes
- the Ant includes pattern, comma separatedexcludes
- the Ant excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of filejava.io.IOException
- in case of failure.@Nonnull public static java.util.List<java.lang.String> getDirectoryNames(@Nonnull java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive) throws java.io.IOException
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 fileisCaseSensitive
- true if case sensitivejava.io.IOException
- in case of failure@Nonnull public static java.util.List<java.lang.String> getFileAndDirectoryNames(java.io.File directory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories)
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 fileisCaseSensitive
- true if case sensitivegetFiles
- true to include regular filesgetDirectories
- true to include directories@Deprecated public static void copyDirectory(@Nonnull java.io.File sourceDirectory, @Nonnull java.io.File destinationDirectory) throws java.io.IOException
org.apache.commons.io.FileUtils.copyDirectory()
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 existjava.io.IOException
- if any@Deprecated public static void copyDirectory(@Nonnull java.io.File sourceDirectory, @Nonnull java.io.File destinationDirectory, @Nullable java.lang.String includes, @Nullable java.lang.String excludes) throws java.io.IOException
org.apache.commons.io.FileUtils.copyDirectory()
sourceDirectory
- the source directorydestinationDirectory
- the target directoryincludes
- Ant include patternexcludes
- Ant exclude patternjava.io.IOException
- if the source is a file or cannot be copiedgetFiles(File, String, String)
@Deprecated public static void copyDirectoryStructure(@Nonnull java.io.File sourceDirectory, @Nonnull java.io.File destinationDirectory) throws java.io.IOException
org.apache.commons.io.FileUtils.copyDirectory()
Note:
sourceDirectory
must exist.
sourceDirectory
- the existing directory to be copieddestinationDirectory
- the new directory to be createdjava.io.IOException
- if anyprivate static void copyDirectoryStructure(@Nonnull java.io.File sourceDirectory, @Nonnull java.io.File destinationDirectory, java.io.File rootDestinationDirectory, boolean onlyModifiedFiles) throws java.io.IOException
java.io.IOException
@Deprecated public static void rename(@Nonnull java.io.File from, @Nonnull java.io.File to) throws java.io.IOException
java.nio.Files.move()
This will remove to
(if it exists), ensure that
to
's parent directory exists and move
from
, which involves deleting from
as
well.
from
- the file to moveto
- the new file namejava.io.IOException
- if anything bad happens during this process.
Note that to
may have been deleted already when this happens.@Deprecated public static java.io.File createTempFile(@Nonnull java.lang.String prefix, @Nonnull java.lang.String suffix, @Nullable java.io.File parentDir)
java.nio.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.
prefix
- prefix before the random numbersuffix
- file extension; include the '.'parentDir
- directory to create the temporary file in -java.io.tmpdir
used if not specifiedprivate static int positiveRandom(java.util.Random rand)
public static void copyFile(@Nonnull java.io.File from, @Nonnull java.io.File to, @Nullable java.lang.String encoding, @Nullable FileUtils.FilterWrapper... wrappers) throws java.io.IOException
from
- the file to copyto
- the destination fileencoding
- the file output encoding (only if wrappers is not empty)wrappers
- array of FileUtils.FilterWrapper
java.io.IOException
- if an IO error occurs during copying or filteringpublic static void copyFile(@Nonnull java.io.File from, @Nonnull java.io.File to, @Nullable java.lang.String encoding, @Nullable FileUtils.FilterWrapper[] wrappers, boolean overwrite) throws java.io.IOException
from
- the file to copyto
- the destination fileencoding
- 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()java.io.IOException
- if an IO error occurs during copying or filteringprivate static void copyFilePermissions(@Nonnull java.io.File source, @Nonnull java.io.File destination) throws java.io.IOException
source
- the file to copy permissions from.destination
- the file to copy permissions to.java.io.IOException
@Deprecated @Nonnull public static java.util.List<java.lang.String> loadFile(@Nonnull java.io.File file) throws java.io.IOException
file
- the filejava.io.IOException
- if anyprivate static java.nio.charset.Charset charset(java.lang.String encoding)
encoding
- the name or alias of the charset, null or emptyprivate static boolean isValidWindowsFileName(@Nonnull java.io.File f)
":", "*", "?", "\"", "<", ">", "|"
f
- not null filefalse
if the file path contains any of forbidden Windows characters,
true
if the Os is not Windows or if the file path respect the Windows constraints.INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
@Deprecated public static boolean isSymbolicLink(@Nonnull java.io.File file) throws java.io.IOException
java.nio.file.Files.isSymbolicLink(file.toPath())
file
- the file to checkjava.io.IOException
- in case of failure.@Deprecated public static boolean isSymbolicLinkForSure(@Nonnull java.io.File file) throws java.io.IOException
java.nio.file.Files.isSymbolicLink(file.toPath())
file
- the file to checkjava.io.IOException
- in case of failure@Nonnull public static java.io.File createSymbolicLink(@Nonnull java.io.File symlink, @Nonnull java.io.File target) throws java.io.IOException
symlink
- the link nametarget
- the targetjava.io.IOException
- in case of an errorwhich creates a new symbolic link but does
not replace existing symbolic links