Using the SecureDirectoryStream class - Java File Path IO

Java examples for File Path IO:Directory

Introduction

SecureDirectoryStream can be used with applications that depend on tighter security.

This class requires support from the operating system.

Demo Code

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

public class Main {

    public static void main(String args[]) throws IOException {
        Path path = Paths.get("home/docs");
        SecureDirectoryStream<Path> sds = (SecureDirectoryStream) Files.newDirectoryStream(path);
        PosixFileAttributeView view = sds.getFileAttributeView(PosixFileAttributeView.class);
        PosixFileAttributes attributes = view.readAttributes();
        Set<PosixFilePermission> permissions = attributes.permissions();

        for (PosixFilePermission permission : permissions) {
            System.out.print(permission.toString() + ' ');
        }/*from www  .  j  a  v  a  2s  .c o m*/
        System.out.println();
    }
}

Related Tutorials