Java Utililty Methods Path Copy nio

List of utility methods to do Path Copy nio

Description

The list of methods to do Path Copy nio are organized into topic(s).

Method

voidcreateDirectoriesIfNeeded(Path directory)
Creates the specified directory if it does not exists.
if (!Files.exists(directory)) {
    Files.createDirectories(directory);
PathcreateDirectoriesIfNotExists(Path path)
create Directories If Not Exists
if (Files.exists(path)) {
    return path;
return Files.createDirectories(path);
booleancreateDirectory(Path directory)
create Directory
try {
    if (!Files.exists(directory)) {
        Files.createDirectories(directory);
    return true;
} catch (IOException e) {
    return false;
voidcreateDirectory(Path outDir, boolean cleanExisting)
create Directory
if (cleanExisting) {
    cleanDirectory(outDir);
Files.createDirectories(outDir);
PathcreateDirectory(Path parent, String name)
Creates the directory with name in the parent directory parent
Path result = null;
try {
    if (name != null) {
        result = parent.resolve(name);
    } else {
        result = parent;
    if (!Files.exists(result)) {
...
voidcreateDirectoryIfNotExists(Path path)
Check specified directory.
try {
    Files.createDirectories(path);
} catch (FileAlreadyExistsException ignored) {
voidcreateDirectoryRecursively(Path dir)
Attempts to create a directory given a String path.
try {
    Files.createDirectories(dir);
} catch (IOException e) {
    throw new IOException("Exception while trying to create directory: " + e);
if (!dir.toFile().exists()) {
    throw new IOException("Failed to verify directory creation - directory does not exist.");
voidcreateDirectoryRecursively(String dirName)
create Directory Recursively
Path newDirectoryPath = Paths.get(dirName);
if (Files.exists(newDirectoryPath)) {
    throw new java.nio.file.FileAlreadyExistsException("directory " + dirName + " already exists");
Files.createDirectories(newDirectoryPath);
booleanrenameTo(Path from, Path to, CopyOption... options)
rename To
try {
    return Files.move(from, to, options) != null;
} catch (IOException e) {
    return false;
voidwrite(InputStream in, Path path, StandardCopyOption op)

write.

try {
    Files.copy(in, path, op);
} catch (IOException e) {
    throw new RuntimeException(e);