Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

public class Main {

    public static void main(String[] args) throws Exception {

        Path path = Paths.get("c:/home/tutorial/Java/JavaFX/Topic.txt");
        Path new_path = Paths.get("/home/tutorial/Java/JavaFX/new_Topic.txt");
        PosixFileAttributes attr = Files.readAttributes(path, PosixFileAttributes.class);
        attr = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes();

        //use of asFileAttribute
        FileAttribute<Set<PosixFilePermission>> posixattrs = PosixFilePermissions
                .asFileAttribute(attr.permissions());
        try {
            Files.createFile(new_path, posixattrs);
        } catch (IOException e) {
            System.err.println(e);
        }
    }
}