当我向文件添加新的
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());
}
这取决于您运行的平台。
根据 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 上它使用扩展属性。
不确定其他人 - 希望这有帮助:)