2

How to get notified in Java when a USB Drive or a CD/DVD is inserted or ejected?There might be a way better than checking in a loop(say using File.listRoots).

Detect USB Drive in Java

Community
  • 1
  • 1
  • 1
    Unfortunately, I dont think there does. Why don't you want to loop? It wont cost much memory... – Deval Khandelwal Apr 22 '16 at 16:14
  • Just looking for a way to save processor time – Aravind Sharma Apr 22 '16 at 16:15
  • One issue to consider is that the notification system differs by operating system. I would suspect that some JNI to deal with the native O/S could then push a notification, but in a completely cross-platform manner I would not expect a default Java implementation. – KevinO Apr 22 '16 at 16:17
  • It would be helpful if I get an implementation for Windows OS – Aravind Sharma Apr 22 '16 at 16:21
  • 1
    @AravindSharma, but a solution for only one O/S is a bit against the Java approach of running on any platform. Nonetheless, you might look to [Access The Windows API](http://stackoverflow.com/questions/606820/is-there-a-java-library-to-access-the-native-windows-api), and then for [Registering for Device Notification](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363432(v=vs.85).aspx). – KevinO Apr 22 '16 at 16:36
  • Thanks @KevinO.I have started developing my first(JavaFX desktop) application two months ago and not ashamed to mention that i am a novice.It would be really helpful if you post a snippet.Hope I am not asking too much! – Aravind Sharma Apr 22 '16 at 18:32

0 Answers0