1

When I add a new UserDefinedFileAttributeView attribute to a file, where does Java store this information? There are no additional files in the directory, the file does not have any new attributes or details when I view the file properties.

My code:

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());
}
Andrew Gaul
  • 2,296
  • 1
  • 12
  • 19
gwin003
  • 7,432
  • 5
  • 38
  • 59
  • Did you check your user directories and `programdata` directories... I would recommend doing a hard drive search, will be the fastest way to find the file :) – James Oravec Apr 23 '13 at 14:46
  • Any thoughts on what to search for? Haha, I have no idea what file name/type Java would use – gwin003 Apr 23 '13 at 14:52

2 Answers2

2

These metadata are stored using file system's "extended file attributes" (see wikipedia).

I could not find any comprehensive list of file systems being supported (it is definitely JVM specific), so you should definitely test in on all platforms you plan to support. But this answer lists some and this mentions some details about Linux. Hope this helps.

Community
  • 1
  • 1
Foyta
  • 510
  • 1
  • 7
  • 8
0

It depends on the platform you're running under.

As per the OpenJDK documentation: The details of such emulation are highly implementation specific and therefore not specified.

However testing on Windows indicates it uses NTFS Alternate Data Streams:

PS C:\test> Get-Item -Path C:\test\asdf.txt -stream *


   FileName: C:\test\asdf.txt

Stream                   Length
------                   ------
:$DATA                        0
myaltstream                1337

On linux it uses extended attributes.

Not sure about others - hope this helps :)

bly
  • 1,532
  • 1
  • 12
  • 19