java - 无法导入 WindowsFileAttributes

标签 java windows file-attributes

我使用BasicFileAttributes在Windows中获取Java中的属性,如下所示:

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);
    }
}

上面的输出类似于:

sun.nio.fs.WindowsFileAttributes@a1234567

因此我知道 readAttributes 返回一个 WindowsFileAttributes 对象。现在我想将 BasicFileAttributes 转换为 WindowsFileAttributes 并使用它的方法。但我无法导入和使用 WindowsFileAttributes。我收到如下错误:

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)

如何修复此错误?

最佳答案

无法使用 sun.* 内的类。

一种方法是使用 JNA 访问 native Windows 函数,如下所述:Get unique file id in Windows with Java?

关于java - 无法导入 WindowsFileAttributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48258290/

相关文章:

java - org.hibernate.SQLQuery 输出到对象

java - 无法获取 EntityManager 的实例?

php - Ubuntu 到 Windows + php/mysql xml 脚本没有响应

Java NTFS 压缩属性

inno-setup - Inno Setup 安装后隐藏文件夹

java - doLayout 和 include in a template in 'Java Play!' 有什么区别?

java - 当主键自动递增时,如何使用 JPA (EclipseLink) 从数据库中获取特定的 "row"?

windows - 设置 EXE 版本信息

python - Python 脚本、代理和 Microsoft Forefront - 自动身份验证

c# - LINQ 查询中无法访问的表达式代码