This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Mac OS and the fly likes Returning the Volumes on a Mac in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Returning the Volumes on a Mac in Java" Watch "Returning the Volumes on a Mac in Java" New topic
Author

Returning the Volumes on a Mac in Java

Richard M Hardy
Greenhorn

Joined: Mar 22, 2009
Posts: 3
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:



However...

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 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

...

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?
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
Hi I have wrote a small piece of code to test what you are saying. however I didn't get any problems. I have a mac os 10.5.6, this is the code.



in addition i have plugged an USB flash and run the program and i got:
Macintosh HD
PHILIPS UFD

then i unplugged the flash USB without removing it safely and the result was as if it was removed in a safe way. I don't know if its only the differences of OS. however for me everything works fine.


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Richard M Hardy
Greenhorn

Joined: Mar 22, 2009
Posts: 3
I can do that too. And also read things like isFile(), isDirectory() (but not getFreeSpace() which returns an unsupportedError - or something like that)

Could you try this on your one:

Richard M Hardy
Greenhorn

Joined: Mar 22, 2009
Posts: 3
Should have put:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

"Richard MH", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Returning the Volumes on a Mac in Java
 
Similar Threads
Volume free space
Search FIle System for Pattern Match
how to increase heap size with eclipse?
Retrieve list of drives in Win and Mac OSX
what is Abstraction