【问题标题】:Java UserDefinedFileAttributeViewJava 用户定义文件属性视图
【发布时间】:2013-04-23 14:13:29
【问题描述】:

当我向文件添加新的UserDefinedFileAttributeView 属性时,Java 将这些信息存储在哪里? 目录中没有其他文件,查看文件属性时该文件没有任何新属性或细节。

我的代码:

String versionAttrName = "report.version";
try {           
    Path path = FileSystems.getDefault().getPath(filePath, "");
    UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
    view.write(versionAttrName, Charset.defaultCharset().encode(newVersion));
} catch (IOException e) {
    System.out.println("7 - Error saving version to file! - "+ filePath + " - " + e.getMessage());
}

【问题讨论】:

  • 你检查你的用户目录和programdata 目录了吗...我建议你做一个硬盘搜索,这将是找到文件的最快方法:)
  • 对要搜索的内容有什么想法吗?哈哈,我不知道 Java 会使用什么文件名/类型

标签: java nio xattr


【解决方案1】:

这些元数据使用文件系统的“扩展文件属性”存储(参见wikipedia)。

我找不到任何受支持的文件系统的完整列表(它肯定是特定于 JVM 的),因此您绝对应该在您计划支持的所有平台上进行测试。但是this 回答列出了一些,this 提到了一些关于 Linux 的细节。希望这会有所帮助。

【讨论】:

    【解决方案2】:

    这取决于您运行的平台。

    根据 OpenJDK 文档:The details of such emulation are highly implementation specific and therefore not specified.

    但在 Windows 上的测试表明它使用 NTFS 备用数据流:

    PS C:\test> Get-Item -Path C:\test\asdf.txt -stream *
    
    
       FileName: C:\test\asdf.txt
    
    Stream                   Length
    ------                   ------
    :$DATA                        0
    myaltstream                1337
    

    在 linux 上它使用扩展属性。

    不确定其他人 - 希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 2015-02-26
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      相关资源
      最近更新 更多