问题
Is there a way to detect all SD Card drives connected to a Desktop computer? In Windows, SD Cards are visually distinct from other devices like built-in hard drives or similar. Is there a way to tell if a drive is an SD Card drive or not?
A Java way of listing all available filesystem roots for example is using the listRoots() method but it cannot tell the filesystem types such as external, internal, OS drive or whatever.
Is this even possible in pure Java?
Note:
I'm not asking to detect the Android phone SD Card since these are the results when searching for my question.
回答1:
This answer solved it.
Example code:
USBDeviceDetectorManager manager = new USBDeviceDetectorManager();
List<USBStorageDevice> usbStorageDevices = manager.getRemovableDevices();
for(USBStorageDevice usbStorageDevice : usbStorageDevices)
{
System.out.println(usbStorageDevice.getSystemDisplayName());
System.out.println(usbStorageDevice.getDeviceName());
System.out.println(usbStorageDevice.getRootDirectory());
}
I have my SD card
, NAS
, C:
and D:
drives connected. The following is printed:
SANDISK (E:)
SANDISK
E:\
As expected, only one result is returned because the SD card
is treated as USB
due to the USB reader
being plugged into my laptop.
来源:https://stackoverflow.com/questions/34676452/detecting-verifying-sd-card-drive