title: Find the directory for a FileStore
body: <p>I'm trying to find a way to detect when a flash drive has been plugged into my computer. So far, the solution I found was to poll <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getFileStores%28%29"><code>FileSystem#getFileStores</code></a> for changes. This does indeed tell me when the flash drive has been inserted, but as far as I can tell there is no way to retrieve the location for it. <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileStore.html#type%28%29"><code>FileStore#type</code></a> and <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileStore.html#name%28%29"><code>FileStore#name</code></a> both seem highly unreliable as their return value is implementation specific, but they appear to be the only methods that might return any relevant information that might help find the directory for the <code>FileStore</code>.</p>
  
  <p>With that in mind, the following code:</p>
  
  <pre><code>public class Test {
      public static void main(String[] args) throws IOException {
          for (FileStore store : FileSystems.getDefault().getFileStores()) {
              System.out.println(store);
              System.out.println("\t" + store.name());
              System.out.println("\t" + store.type());
              System.out.println();
          }
      }
  }
  </code></pre>
  
  <p>Gave me this output:</p>
  
  <pre><code>/ (/dev/sda5)
      /dev/sda5
      ext4
  
  /* snip */
  
  /media/TI103426W0D (/dev/sda2)
      /dev/sda2
      fuseblk
  
  /media/flashdrive (/dev/sdb1)
      /dev/sdb1
      vfat
  </code></pre>
  
  <p>As it turns out, <code>FileStore#type</code> returns the format of the drive and <code>FileStore#name</code> returns the location of the device file for the drive. As far as I can tell, the only method which has the location of the drive is the <code>toString</code> method, but extracting the path name out of it seems dangerous because I'm not sure how well that particular solution would hold up on other operating systems and future versions of Java.</p>
  
  <p>Is there something I'm missing here or is this simply not possible purely with Java?</p>
  
  <p>System Information:</p>
  
  <pre><code>$ java -version
  java version "1.7.0_03"
  OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu2)
  OpenJDK Client VM (build 22.0-b10, mixed mode, sharing)
  
  $ uname -a
  Linux jeffrey-pc 3.2.0-24-generic-pae #37-Ubuntu SMP Wed Apr 25 10:47:59 UTC 2012 i686 athlon i386 GNU/Linux
  </code></pre>