Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get default FileAttributs to create a Path

Tags:

java

nio

I want to create a Path with Files.createFile(path, FileAttributes...)

How can I get a set of default FileAttributes to create a File on Windows?

like image 763
Christian Avatar asked Dec 18 '25 06:12

Christian


1 Answers

Here is basic example for your cause.

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

        BasicFileAttributes thisFileBasicAttributes = null;
        Path pathOfThisFile = Paths.get("/myKey.store");
        System.out.println(pathOfThisFile);
        try{
        thisFileBasicAttributes = Files.readAttributes(pathOfThisFile, BasicFileAttributes.class);
        Object fileKeyBasic = thisFileBasicAttributes.fileKey();
        String output = "Basic: " + fileKeyBasic.toString();
        System.out.println(output);
        }
        catch(IOException exception)
        {
            System.err.println("JVM reported an exception, please take a look at" + exception);
        }

    }
like image 77
MS90 Avatar answered Dec 19 '25 21:12

MS90