public final class PathUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static DeleteOption[] |
EMPTY_DELETE_OPTION_ARRAY
Empty
LinkOption array. |
static java.nio.file.FileVisitOption[] |
EMPTY_FILE_VISIT_OPTION_ARRAY
Empty
FileVisitOption array. |
static java.nio.file.LinkOption[] |
EMPTY_LINK_OPTION_ARRAY
Empty
LinkOption array. |
static java.nio.file.OpenOption[] |
EMPTY_OPEN_OPTION_ARRAY
Empty
OpenOption array. |
| Modifier and Type | Method and Description |
|---|---|
static Counters.PathCounters |
cleanDirectory(java.nio.file.Path directory)
Cleans a directory including sub-directories without deleting directories.
|
static Counters.PathCounters |
cleanDirectory(java.nio.file.Path directory,
DeleteOption... options)
Cleans a directory including sub-directories without deleting directories.
|
static Counters.PathCounters |
copyDirectory(java.nio.file.Path sourceDirectory,
java.nio.file.Path targetDirectory,
java.nio.file.CopyOption... copyOptions)
Copies a directory to another directory.
|
static java.nio.file.Path |
copyFile(java.net.URL sourceFile,
java.nio.file.Path targetFile,
java.nio.file.CopyOption... copyOptions)
Copies a URL to a directory.
|
static java.nio.file.Path |
copyFileToDirectory(java.nio.file.Path sourceFile,
java.nio.file.Path targetDirectory,
java.nio.file.CopyOption... copyOptions)
Copies a file to a directory.
|
static java.nio.file.Path |
copyFileToDirectory(java.net.URL sourceFile,
java.nio.file.Path targetDirectory,
java.nio.file.CopyOption... copyOptions)
Copies a URL to a directory.
|
static Counters.PathCounters |
countDirectory(java.nio.file.Path directory)
Counts aspects of a directory including sub-directories.
|
static Counters.PathCounters |
delete(java.nio.file.Path path)
Deletes a file or directory.
|
static Counters.PathCounters |
delete(java.nio.file.Path path,
DeleteOption... options)
Deletes a file or directory.
|
static Counters.PathCounters |
deleteDirectory(java.nio.file.Path directory)
Deletes a directory including sub-directories.
|
static Counters.PathCounters |
deleteDirectory(java.nio.file.Path directory,
DeleteOption... options)
Deletes a directory including sub-directories.
|
static Counters.PathCounters |
deleteFile(java.nio.file.Path file)
Deletes the given file.
|
static Counters.PathCounters |
deleteFile(java.nio.file.Path file,
DeleteOption... options)
Deletes the given file.
|
static boolean |
directoryAndFileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2)
Compares the file sets of two Paths to determine if they are equal or not while considering file contents.
|
static boolean |
directoryAndFileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2,
java.nio.file.LinkOption[] linkOptions,
java.nio.file.OpenOption[] openOptions,
java.nio.file.FileVisitOption[] fileVisitOption)
Compares the file sets of two Paths to determine if they are equal or not while considering file contents.
|
static boolean |
directoryContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2)
Compares the file sets of two Paths to determine if they are equal or not without considering file contents.
|
static boolean |
directoryContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2,
int maxDepth,
java.nio.file.LinkOption[] linkOptions,
java.nio.file.FileVisitOption[] fileVisitOptions)
Compares the file sets of two Paths to determine if they are equal or not without considering file contents.
|
static boolean |
fileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2)
Compares the file contents of two Paths to determine if they are equal or not.
|
static boolean |
fileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2,
java.nio.file.LinkOption[] linkOptions,
java.nio.file.OpenOption[] openOptions)
Compares the file contents of two Paths to determine if they are equal or not.
|
static java.util.List<java.nio.file.attribute.AclEntry> |
getAclEntryList(java.nio.file.Path sourcePath)
Reads the access control list from a file attribute view.
|
static boolean |
isEmpty(java.nio.file.Path path)
Returns whether the given file or directory is empty.
|
static boolean |
isEmptyDirectory(java.nio.file.Path directory)
Returns whether the directory is empty.
|
static boolean |
isEmptyFile(java.nio.file.Path file)
Returns whether the given file is empty.
|
static java.nio.file.Path |
setReadOnly(java.nio.file.Path path,
boolean readOnly,
java.nio.file.LinkOption... options)
Sets the given Path to the
readOnly value. |
static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> |
visitFileTree(T visitor,
java.nio.file.Path directory)
Performs
Files.walkFileTree(Path,FileVisitor) and returns the given visitor. |
static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> |
visitFileTree(T visitor,
java.nio.file.Path start,
java.util.Set<java.nio.file.FileVisitOption> options,
int maxDepth)
Performs
Files.walkFileTree(Path,FileVisitor) and returns the given visitor. |
static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> |
visitFileTree(T visitor,
java.lang.String first,
java.lang.String... more)
Performs
Files.walkFileTree(Path,FileVisitor) and returns the given visitor. |
static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> |
visitFileTree(T visitor,
java.net.URI uri)
Performs
Files.walkFileTree(Path,FileVisitor) and returns the given visitor. |
public static final DeleteOption[] EMPTY_DELETE_OPTION_ARRAY
LinkOption array.public static final java.nio.file.FileVisitOption[] EMPTY_FILE_VISIT_OPTION_ARRAY
FileVisitOption array.public static final java.nio.file.LinkOption[] EMPTY_LINK_OPTION_ARRAY
LinkOption array.public static final java.nio.file.OpenOption[] EMPTY_OPEN_OPTION_ARRAY
OpenOption array.public static Counters.PathCounters cleanDirectory(java.nio.file.Path directory) throws java.io.IOException
directory - directory to clean.java.io.IOException - if an I/O error is thrown by a visitor method.public static Counters.PathCounters cleanDirectory(java.nio.file.Path directory, DeleteOption... options) throws java.io.IOException
directory - directory to clean.options - options indicating how deletion is handled.java.io.IOException - if an I/O error is thrown by a visitor method.public static Counters.PathCounters copyDirectory(java.nio.file.Path sourceDirectory, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions) throws java.io.IOException
sourceDirectory - The source directory.targetDirectory - The target directory.copyOptions - Specifies how the copying should be done.java.io.IOException - if an I/O error is thrown by a visitor method.public static java.nio.file.Path copyFile(java.net.URL sourceFile,
java.nio.file.Path targetFile,
java.nio.file.CopyOption... copyOptions)
throws java.io.IOException
sourceFile - The source URL.targetFile - The target file.copyOptions - Specifies how the copying should be done.java.io.IOException - if an I/O error occursFiles.copy(InputStream, Path, CopyOption...)public static java.nio.file.Path copyFileToDirectory(java.nio.file.Path sourceFile,
java.nio.file.Path targetDirectory,
java.nio.file.CopyOption... copyOptions)
throws java.io.IOException
sourceFile - The source file.targetDirectory - The target directory.copyOptions - Specifies how the copying should be done.java.io.IOException - if an I/O error occursFiles.copy(Path, Path, CopyOption...)public static java.nio.file.Path copyFileToDirectory(java.net.URL sourceFile,
java.nio.file.Path targetDirectory,
java.nio.file.CopyOption... copyOptions)
throws java.io.IOException
sourceFile - The source URL.targetDirectory - The target directory.copyOptions - Specifies how the copying should be done.java.io.IOException - if an I/O error occursFiles.copy(InputStream, Path, CopyOption...)public static Counters.PathCounters countDirectory(java.nio.file.Path directory) throws java.io.IOException
directory - directory to delete.java.io.IOException - if an I/O error is thrown by a visitor method.public static Counters.PathCounters delete(java.nio.file.Path path) throws java.io.IOException
The difference between File.delete() and this method are:
File.delete() returns a
boolean.
path - file or directory to delete, must not be nulljava.lang.NullPointerException - if the directory is nulljava.io.IOException - if an I/O error is thrown by a visitor method or if an I/O error occurs.public static Counters.PathCounters delete(java.nio.file.Path path, DeleteOption... options) throws java.io.IOException
The difference between File.delete() and this method are:
File.delete() returns a
boolean.
path - file or directory to delete, must not be nulloptions - options indicating how deletion is handled.java.lang.NullPointerException - if the directory is nulljava.io.IOException - if an I/O error is thrown by a visitor method or if an I/O error occurs.public static Counters.PathCounters deleteDirectory(java.nio.file.Path directory) throws java.io.IOException
directory - directory to delete.java.io.IOException - if an I/O error is thrown by a visitor method.public static Counters.PathCounters deleteDirectory(java.nio.file.Path directory, DeleteOption... options) throws java.io.IOException
directory - directory to delete.options - options indicating how deletion is handled.java.io.IOException - if an I/O error is thrown by a visitor method.public static Counters.PathCounters deleteFile(java.nio.file.Path file) throws java.io.IOException
file - The file to delete.java.io.IOException - if an I/O error occurs.java.nio.file.NoSuchFileException - if the file is a directory.public static Counters.PathCounters deleteFile(java.nio.file.Path file, DeleteOption... options) throws java.io.IOException
file - The file to delete.options - options indicating how deletion is handled.java.io.IOException - if an I/O error occurs.java.nio.file.NoSuchFileException - if the file is a directory.public static boolean directoryAndFileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2)
throws java.io.IOException
path1 - The first directory.path2 - The second directory.java.io.IOException - if an I/O error is thrown by a visitor methodpublic static boolean directoryAndFileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2,
java.nio.file.LinkOption[] linkOptions,
java.nio.file.OpenOption[] openOptions,
java.nio.file.FileVisitOption[] fileVisitOption)
throws java.io.IOException
path1 - The first directory.path2 - The second directory.linkOptions - options to follow links.openOptions - options to open files.fileVisitOption - options to configure traversal.java.io.IOException - if an I/O error is thrown by a visitor methodpublic static boolean directoryContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2)
throws java.io.IOException
path1 - The first directory.path2 - The second directory.java.io.IOException - if an I/O error is thrown by a visitor methodpublic static boolean directoryContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2,
int maxDepth,
java.nio.file.LinkOption[] linkOptions,
java.nio.file.FileVisitOption[] fileVisitOptions)
throws java.io.IOException
path1 - The first directory.path2 - The second directory.maxDepth - See Files.walkFileTree(Path,Set,int,FileVisitor).linkOptions - options to follow links.fileVisitOptions - options to configure the traversaljava.io.IOException - if an I/O error is thrown by a visitor methodpublic static boolean fileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2)
throws java.io.IOException
File content is accessed through Files.newInputStream(Path,OpenOption...).
path1 - the first stream.path2 - the second stream.java.lang.NullPointerException - if either input is null.java.io.IOException - if an I/O error occurs.FileUtils.contentEquals(java.io.File, java.io.File)public static boolean fileContentEquals(java.nio.file.Path path1,
java.nio.file.Path path2,
java.nio.file.LinkOption[] linkOptions,
java.nio.file.OpenOption[] openOptions)
throws java.io.IOException
File content is accessed through Files.newInputStream(Path,OpenOption...).
path1 - the first stream.path2 - the second stream.linkOptions - options specifying how files are followed.openOptions - options specifying how files are opened.java.lang.NullPointerException - if either input is null.java.io.IOException - if an I/O error occurs.FileUtils.contentEquals(java.io.File, java.io.File)public static java.util.List<java.nio.file.attribute.AclEntry> getAclEntryList(java.nio.file.Path sourcePath)
throws java.io.IOException
sourcePath - the path to the file.java.io.IOException - if an I/O error occurs.public static boolean isEmpty(java.nio.file.Path path)
throws java.io.IOException
path - the the given file or directory to query.java.io.IOException - if an I/O error occurspublic static boolean isEmptyDirectory(java.nio.file.Path directory)
throws java.io.IOException
directory - the the given directory to query.java.io.IOException - if an I/O error occurspublic static boolean isEmptyFile(java.nio.file.Path file)
throws java.io.IOException
file - the the given file to query.java.io.IOException - if an I/O error occurspublic static java.nio.file.Path setReadOnly(java.nio.file.Path path,
boolean readOnly,
java.nio.file.LinkOption... options)
throws java.io.IOException
readOnly value.
This behavior is OS dependent.
path - The path to set.readOnly - true for read-only, false for not read-only.options - options indicating how symbolic links are handled.java.io.IOException - if an I/O error occurs.public static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree(T visitor,
java.nio.file.Path directory)
throws java.io.IOException
Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
Note that Files.walkFileTree(Path,FileVisitor) returns the given path.T - See Files.walkFileTree(Path,FileVisitor).visitor - See Files.walkFileTree(Path,FileVisitor).directory - See Files.walkFileTree(Path,FileVisitor).java.io.IOException - if an I/O error is thrown by a visitor methodpublic static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree(T visitor,
java.nio.file.Path start,
java.util.Set<java.nio.file.FileVisitOption> options,
int maxDepth)
throws java.io.IOException
Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
Note that Files.walkFileTree(Path,FileVisitor) returns the given path.T - See Files.walkFileTree(Path,Set,int,FileVisitor).start - See Files.walkFileTree(Path,Set,int,FileVisitor).options - See Files.walkFileTree(Path,Set,int,FileVisitor).maxDepth - See Files.walkFileTree(Path,Set,int,FileVisitor).visitor - See Files.walkFileTree(Path,Set,int,FileVisitor).java.io.IOException - if an I/O error is thrown by a visitor methodpublic static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree(T visitor,
java.lang.String first,
java.lang.String... more)
throws java.io.IOException
Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
Note that Files.walkFileTree(Path,FileVisitor) returns the given path.T - See Files.walkFileTree(Path,FileVisitor).visitor - See Files.walkFileTree(Path,FileVisitor).first - See Paths.get(String,String[]).more - See Paths.get(String,String[]).java.io.IOException - if an I/O error is thrown by a visitor methodpublic static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree(T visitor,
java.net.URI uri)
throws java.io.IOException
Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
Note that Files.walkFileTree(Path,FileVisitor) returns the given path.T - See Files.walkFileTree(Path,FileVisitor).visitor - See Files.walkFileTree(Path,FileVisitor).uri - See Paths.get(URI).java.io.IOException - if an I/O error is thrown by a visitor methodCopyright © 2010 - 2022 Adobe. All Rights Reserved