• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Java library to get a list of all usb storage devices connected to the computer.

USB Drive Detector

version

A Java library to get a list of all usb storage devices connected to the computer and has the capability of unmount them. It works on the three main operating systems (Windows, Linux and OS X).

Maven dependency

To include this library in your project, add the following on your pom.xml:

<project>
    <dependencies>
        <!-- New dependency -->
        <dependency>
            <groupId>net.samuelcampos</groupId>
            <artifactId>usbdrivedetector</artifactId>
            <version>2.2.1</version>
        </dependency>
    </dependencies>
</project>

Usage examples

USBDeviceDetectorManager driveDetector = new USBDeviceDetectorManager();

// Display all the USB storage devices currently connected
driveDetector.getRemovableDevices().forEach(System.out::println);

// Add an event listener to be notified when an USB storage device is connected or removed
driveDetector.addDriveListener(System.out::println);

// Unmount a device
driveDetector.unmountStorageDevice(driveDetector.getRemovableDevices().get(0));

Once you invoke addDriveListener, your application keep running because it will internally create an ScheduledExecutorService. To finish your application, just invoke the close method;

    // Shutdown an initialized USBDeviceDetectorManager
    driveDetector.close();