list - Detect multiple connected devices in Java -


I want to write a Java code that will meet the following requirements:

  1. List all devices connected to the laptop
  2. Allow users to choose which device should be used by the java program

For example, when there are 2 USB devices, the Java program will detect them and then convert them to (e.g. F: \, G :) Will be listed. After this, users can choose which device to use. What is the way to do this?

I found that this website is useful that my thumbnail is connected, however, it is not able to detect more than one device.

detect.java

  Find public squares {public string USBDetect () {string drive litter = ""; FileSystemView fsv = FileSystemView.getFileSystemView (); File [f] = file. List root (); For (int i = 0; i  ("Removable"). type. )) {//log.info ("Detected PEN Drive:" + drive + "-" + displayName); Drive litter = drive; break; }} / * If (driveLetter.equals ("")) {System.out.println ("Not Found!"); } Else {System.out.println (drive liter); } * / / // system. Out.printlean (david letter); Return drive litter; }}  

list. Java

  public category list {public static zero main (string [] args) {file [units} = file.listRoots (); (File unit: units) {System.out.println (unit.getAbsolutePath ()); }}}  

This code helps to detect more than 1 removable drive, but it also lists local drives. I believe that I find.java Should be included in some parts so that it can only detect removable drives. 2 and 3. As I have not tried so far because I do not know how to start, because I have not found any relevant website for reference. I hope you can provide me any useful website or code which can meet the requirements above. Sorry I'm new to Java

  import java.io.file; Import javax.swing.filechooser.FileSystemView; Detects Public Square {Public Stable Zero Main (String [] Args) {Test Test = New Detect (); Test.USBDetect (); } Public Zero USBDetect () {String Drive Litter = ""; FileSystemView fsv = FileSystemView.getFileSystemView (); File [f] = file. List root (); For (int i = 0; i  ("Removable"). type. )) {//log.info ("Detected PEN Drive:" + drive + "-" + displayName); Drive litter = drive; Println (driveletter); }} / * If (driveLetter.equals ("")) {System.out.println ("Not Found!"); } Else {System.out.println (drive liter); } * / / // system. Out.printlean (david letter); }}  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -