Returning Volumes in Java

Discussion in 'Mac Programming' started by richardmh, Mar 22, 2009.

  1. richardmh macrumors newbie

    Mar 22, 2009
    I'm developing a Java App in Netbeans, one of the requirements is it has to look at drives frequently to see if a new memory stick has been inserted, and if it has, take
    a look to see what's on it, and if there's a configuration file specific to the app. then it reads it and looks at all the data on the memory stick for some specific stuff.

    This all works perfectly on PC.

    Of course on Mac the 'drives' are Volumes. No problem, just concantenate the File array you get from File.listRoots() with this one:

    File [] osxVols = new File("/Volumes").listFiles();


    If you unplug a memory stick from my mac (10.4.11), without first ejecting it, of course it complains, and it seems the Volume isn't deleted from /Volumes

    so, thinks I, just pre-process osxVols a bit to see if each file in /Volumes actually exists and discard the ones which don't, this should return a 'true' picture of which volumes are really there.

    But in my iteration over all the File items in osxVols

    if (osxVols.exists())...

    Always throws a java.lang.NullPointerException

    Even on volumes I KNOW exist.

    So what's going on?

    Is there a better way to get a 'correct' list of File objects representing Volume roots?

Share This Page