title: Issues writing file metadata with Java nio
body: <p>I'm looking to add a custom metadata tag to any type of file using  functionality from java.nio.file.Files. I have been able to read metadata correctly, but am having issues whenever I try to set metadata.</p>
  
  <p>I've tried to set a custom metadata element with a plain string using Files.setAttribute with the following</p>
  
  <pre><code>    Path photo = Paths.get("C:\\Users\\some\\picture\\path\\2634.jpeg");
      try{
          BasicFileAttributes attrs = Files.readAttributes(photo, BasicFileAttributes.class);
          Files.setAttribute(photo, "user:tags", "test");
          String attribute = Files.getAttribute(photo, "user:tags").toString();
          System.out.println(attribute);
      }
      catch (IOException ioex){
          ioex.printStackTrace();
      }
  </code></pre>
  
  <p>but end up with the following error : </p>
  
  <p>Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.nio.ByteBuffer</p>
  
  <p>if I try to cast that string to a ByteBuffer like so  </p>
  
  <pre><code>    Path photo = Paths.get("C:\\Users\\some\\picture\\path\\2634.jpeg");
      try{
          BasicFileAttributes attrs = Files.readAttributes(photo, BasicFileAttributes.class);
          Files.setAttribute(photo, "user:tags", ByteBuffer.wrap(("test").getBytes("UTF-8")));
          String attribute = Files.getAttribute(photo, "user:tags").toString();
          System.out.println(attribute);
      }
      catch (IOException ioex){
          ioex.printStackTrace();
      }
  </code></pre>
  
  <p>instead of outputting the text 'test', it outputs the strange character string '[B@14e3f41'  </p>
  
  <p>What is the proper way to convert a String to a bytebuffer and have it be convertable back into a string, and is there a more customizable way to modify metadata on a File using java?</p>