title: File id for keeping track of file changes in Java?
body: <p>I'm trying to find a way to keep track of files even when they are moved or renamed in the file system.</p>
  
  <p>One idea I had was to use the new UserDefinedFileAttributeView in Java 7 and create a custom file attribute as a sort of custom id. I thought that this might work on different platforms (Windows and Mac primarily). But I can't get it to work. Even trying the example on <a href="http://docs.oracle.com/javase/tutorial/essential/io/fileAttr.html" rel="nofollow noreferrer">this page</a>, when I get to this line:</p>
  
  <pre><code>UserDefinedFileAttributeView view = Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
  </code></pre>
  
  <p>I only get a null value for the view variable, and then the program stops with a nullpointer exception.</p>
  
  <p>I then found that there is a perhaps easier way to do this for Mac at least: use the BasicFileAttributes fileKey attribute. I tried this, and the fileKey seems to stay the same even if I move the file or rename it. However, it also says that this functionality is platform dependent, and I remember reading somewhere that it doesn't work on Windows...</p>
  
  <p>So first of all, is the fileKey method a stable way of doing this on Mac? And if so, what can I do for the same functionality for Windows? Anyone know why I get null on the UserDefinedFileAttributeView? Because if I could get that to work it should be cross-platform I guess.</p>
  
  <p>This is not something that needs to be super robust and scalable, it is just a small helper application I'm developing, but it needs to be at least reliable in identifying files when moved or renamed...</p>