• Post Reply Bookmark Topic Watch Topic
  • New Topic

File Chooser Tree question  RSS feed

 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've developed a nifty little file chooser tree (JTree) and I'm left with one little tiny problem: how do I search a computer and find out all the drives that are available to me? Is there another way besides making a loop to go from a:\-z:\, instantiating files, and using File.exists()?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a static method "listRoots()" in java.io.File which gives you an array of File objects, one for each "filesystem root" . Under Windows, it gives one entry for each drive.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hah, I've been programming too long... When the answer is just smack dab in front of my face the whole time.. Time to take a nap!
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your next trick, can you tell me how to make it so that I can stop windows from asking me to put a disk in drive A: when I instatiate the file tree?
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.io.File.listRoots() won't check for floppy.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but it will list the floppy drive as a root!
So when I call rootFile.exists() on the floppy, windows asks me to put in a floppy disk.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you calling exists() on each root? They exist, or they wouldn't
be in the list. Now, what's -on- them, that's another story.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... that's a good point.
I think I had that leftover from when I was merely iterating a->z looking for drives
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!