tags:

views:

92

answers:

2
+1  A: 

While I didn't see it in your question, I presume you are very familiar with File.listRoots() method which returns an array of well, file roots.

Then, you could just iterate over them, and try to identify if they are flash drives. Some hacks may be like:

File[] roots = File.listRoots();

if (roots == null) {
  // you have a different problem here.  Is it even a computer we are talking about?
}

// Iterate through roots
for (File root : roots) {
    if (root.canWrite()) {  // Or, you could use File.createTempfile with that folder
        // if root does not contain some well know files
        // Or, if root contains some well known files
        // Based on these 2 hacks, or possible other characteristics, you may be reasonably sure
    }
}

That's all I can offer. A lot more can be done with more native programs, and then invoking them from the Java program.

Amrinder Arora
Ok, I suppose you're suggesting I should create conditions to check if it's a known device. e.g.: if my root contains `Documents and Settings` directory then I'm on windows xp. Right?
dierre
Well, to find out the OS is more straight forward (System.getProperty("os.name") etc). I was referring to distinguishing external hard drive from other possible drives (Hard Disk Partition, iPod, CD, DVD etc).
Amrinder Arora
A: 

You can check the javax.usb project. Currently there are two certified implementations, for Linux and BSD, and a implementation for windows (as it seems, its still not complete, but I supose it allows you to list the USB devices conected).

But I'm not sure if the posibility of listing only USB drives (instead all drives like in @Amrinder Arora answer) worth adopt a new library set and struggle with a semi-complete implementation...

Tomas Narros