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

voidcopyFile(Path source, Path target, boolean prompt, boolean preserve)
Copy source file to target location.
CopyOption[] options = (preserve) ? new CopyOption[] { COPY_ATTRIBUTES, REPLACE_EXISTING }
        : new CopyOption[] { REPLACE_EXISTING };
if (!prompt || Files.notExists(target)) 
    try {
        Files.copy(source, target, options);
    } catch (IOException x) {
        System.err.format("Unable to copy: %s: %s%n", source, x);
...
voidcopyFile(Path source, Path target, boolean prompt, boolean preserve)
Copy source file to target location.
if (!prompt || Files.notExists(target)) {
    try {
        Files.copy(source, target);
    } catch (IOException x) {
        System.err.format("Unable to copy: %s: %s%n", source, x);
voidcopyFile(Path srcFile, Path srcDir, Path dstDir)
copy File
Path relative = srcDir.relativize(srcFile);
Path dstFile = dstDir.resolve(relative);
if (Files.exists(dstFile) && Files.isDirectory(dstFile)) {
    return; 
Files.copy(srcFile, dstFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
voidcopyFile(String srcPath, String destPath)
copy File
File srcFile = new File(srcPath);
File destFile = new File(destPath);
if (!destFile.exists())
    new File(destPath).mkdirs();
destFile = new File(destPath);
Files.copy(srcFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
BooleancopyFile(String urlPath, String outFile)
copy File
return copyFile(urlPath, outFile, false);
voidcopyFileFromResourcesToServer(String resourceFile, Path targetDirectory, boolean override)
copy File From Resources To Server
if (resourceFile == null || "".equals(resourceFile)) {
    return;
Path sourcePath = Paths.get(ClassLoader.getSystemResource(resourceFile).toURI());
Path targetPath = Paths.get(targetDirectory.toString(), sourcePath.getFileName().toString());
if (override || Files.notExists(targetPath)) {
    Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
voidcopyFiles()
Copying resource files to the carbon home location.
copy(Paths.get("src", "test", "resources", "conf", "carbon.yml"),
        Paths.get(System.getProperty("carbon.home"), "conf", "carbon.yml"));
copy(Paths.get("src", "test", "resources", "conf", "log4j2.xml"), Paths.get("conf", "log4j2.xml"));
copy(Paths.get("src", "test", "resources", "conf", "osgi", "launch.properties"),
        Paths.get("conf", "osgi", "launch.properties"));
copy(Paths.get("src", "test", "resources", "conf", "deployment.yml"), Paths.get("conf", "deployment.yml"));
copy(Paths.get("src", "test", "resources", "deployment", "uufapps", "README.txt"),
        Paths.get("deployment", "uufapps", "README.txt"));
...
voidcopyFiles(String srcPath, String destPath)
copy Files
File srcDir = new File(srcPath);
File destDir = new File(destPath);
if (!destDir.exists())
    new File(destPath).mkdirs();
destDir = new File(destPath);
Files.copy(srcDir.toPath(), destDir.toPath(), StandardCopyOption.REPLACE_EXISTING);
voidcopyFiles(String urlDir, String outPath)
Copy files in url directory to local path
copyFiles(urlDir, outPath, false);
voidcopyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List filenames)
copy Files And Apply Permissions
for (String fileName : filenames) {
    Files.copy(sourceDir.resolve(fileName), targetDir.resolve(fileName));
    try {
        Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
        perms.add(PosixFilePermission.OWNER_READ);
        perms.add(PosixFilePermission.OWNER_WRITE);
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        perms.add(PosixFilePermission.GROUP_READ);
...