I don't know how to use readAttributes
method of Files
class, to access all the file attributes at once. My problem is that I want to print all the attributes in bulk, without calling methods.
I don't want to call methods one by one, as shown below:
Path file = ...;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
System.out.println("isDirectory: " + attr.isDirectory());
System.out.println("isOther: " + attr.isOther());
System.out.println("isRegularFile: " + attr.isRegularFile());
System.out.println("isSymbolicLink: " + attr.isSymbolicLink());
System.out.println("size: " + attr.size());
I would like to access all the BasicFileAttribute at once. If we cannot access all attributes with readAttributes at once,then is there any other way to do this.
This is another example of how to use readAttributes()
method of the class BasicFileAttributes
class:
Path path = Paths.get("C:\\Users\\jorgesys\\workspaceJava\\myfile.txt");
BasicFileAttributes attr;
try {
attr = Files.readAttributes(path, BasicFileAttributes.class);
System.out.println("Creation time: " + attr.creationTime());
System.out.println("Last access time: " + attr.lastAccessTime());
System.out.println("Last modified time: " + attr.lastModifiedTime());
} catch (IOException e) {
System.out.println("oops un error! " + e.getMessage());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With