I use BasicFileAttributes to get the attributes in Java in Windows as below:
public class Test {
public static void main(String[] args) throws Exception {
BasicFileAttributes attr = null;
Path path = Paths.get("some","file.txt");
attr = Files.readAttributes(path, BasicFileAttributes.class);
System.out.println(attr);
}
}
The output of the above is something like:
sun.nio.fs.WindowsFileAttributes@a1234567
Hence I understand that readAttributes is returning a WindowsFileAttributes object. Now I want to cast BasicFileAttributes into WindowsFileAttributes and use its methods. But I am unable to import and use WindowsFileAttributes. I get error like:
java: package sun.nio.fs is not visible
(package sun.nio.fs is declared in module java.base, which does not export it to the unnamed module)
How do I fix this error?