• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Retrieve list of drives in Win and Mac OSX

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a small PC Java application that I am 'quickly' porting to Mac OS X. To get the list of drives, it's currently using:

File.listRoots()

I got it working calling:

File.listRoots()[0].listFiles((java.io.FilenameFilter) new NameFileFilter("Volumes"))[0].listFiles()

but I don't really like it and just wonder if there's a cleaner way to deal with drives in multi-platform environment.

Looks like a quite common problem but I can't find a reasonable solution. Unfortunately I can't change to much the windows code...

Am I looking in the wrong direction?

Renato
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mac OS X, like all UNIX-based systems, doesn't really have the clear-cut notion of "drives" the way that Windows does; there's a single file system within which various physical drives are mounted. Your "Volumes" list is really the only way to get this information from Java.

I'm going to move this to our Mac OS X forum, just in case there's a platform-specific trick I don't know about.
[ May 12, 2006: Message edited by: Ernest Friedman-Hill ]
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EFH is correct; there really isn't any concept of physical drives the way that there is in Windows. UNIX systems abstract the concept to volumes.

The content of the /Volumes "folder" is about as close as you are going to get to a similar concept. But be aware that mounted DVDs, CDs, USB "thumb drives", external firewire/USB2 drives, and even mounted disk images will also appear in this folder. It can even (usually created by accident) have hard-drive folders in it.
 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your feedback!

Cheers,

Renato
 
rubbery bacon. crispy tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!