Detecting/Verifying SD Card Drive

痴心易碎 提交于 2019-12-08 09:40:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!