Java Path Copy nio copyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List filenames)

Here you can find the source of copyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List filenames)

Description

copy Files And Apply Permissions

License

Mozilla Public License

Declaration

public static void copyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List<String> filenames)
            throws IOException 

Method Source Code

//package com.java2s;
/**/*from  www  .  j a  v  a  2  s  .c  om*/
 * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;

import java.nio.file.attribute.PosixFilePermission;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
    public static void copyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List<String> filenames)
            throws IOException {
        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);
                perms.add(PosixFilePermission.GROUP_WRITE);
                perms.add(PosixFilePermission.GROUP_EXECUTE);
                perms.add(PosixFilePermission.OTHERS_READ);
                perms.add(PosixFilePermission.OTHERS_WRITE);
                perms.add(PosixFilePermission.OTHERS_EXECUTE);
                Files.setPosixFilePermissions(targetDir.resolve(fileName), perms);
            } catch (Throwable t) {

            }

        }

    }
}

Related

  1. copyFile(String urlPath, String outFile)
  2. copyFileFromResourcesToServer(String resourceFile, Path targetDirectory, boolean override)
  3. copyFiles()
  4. copyFiles(String srcPath, String destPath)
  5. copyFiles(String urlDir, String outPath)
  6. copyFilesRecursively(final Path from, final Path to)
  7. copyFileToArchive(InputStream srcInputStream, Path destPath)
  8. copyFileToDataFolder(ClassLoader cl, String resourceName, Path targetFolder, boolean replace)
  9. copyRecursive(Path source, Path target, CopyOption... options)