USB(记忆棒)或任何其他驱动程序检测并在JAVA中列出其内容

USB(记忆棒)或任何其他驱动程序检测并在JAVA中列出其内容,java,usb,driver,detection,sample,Java,Usb,Driver,Detection,Sample,嘿,伙计们,我正在编写简单的USB检测java应用程序,我无法检测我的USB驱动程序或任何其他驱动程序,我如何才能添加驱动程序检测?是否有任何方法或示例java应用程序可以检测驱动程序及其内容?任何帮助都将不胜感激 如何将以下代码添加到我的应用程序 public class USBdetection { public static void main(String[] args) { String[] letters = new String[]{ "E", "F", "G", "H",

嘿,伙计们,我正在编写简单的USB检测java应用程序,我无法检测我的USB驱动程序或任何其他驱动程序,我如何才能添加驱动程序检测?是否有任何方法或示例java应用程序可以检测驱动程序及其内容?任何帮助都将不胜感激

如何将以下代码添加到我的应用程序

public class USBdetection 
{
public static void main(String[] args)
{   
String[] letters = new String[]{ "E", "F", "G", "H", "I" ,"J","K", "L","M", "N"};
File[] Externaldrives = new File[letters.length];
boolean[] FoundDrive = new boolean[letters.length];

// init the file objects and the initial drive state

    for ( int i = 0; i < letters.length; ++i )
{
Externaldrives[i] = new File(letters[i]+":/");

FoundDrive[i] = Externaldrives[i].canRead();
}

System.out.println("Waiting for device, Please Wait");

// Search each drive
while(true)
{
for ( int i = 0; i < letters.length; ++i )
{
boolean pluggedIn = Externaldrives[i].canRead();

// if the state has changed output a message
if ( pluggedIn != FoundDrive[i] )
{
if ( pluggedIn )
System.out.println("Drive "+letters[i]+" has been plugged in");

FoundDrive[i] = pluggedIn;
}

}

}
}
}k
公共类USB检测
{
公共静态void main(字符串[]args)
{   
字符串[]字母=新字符串[]{“E”、“F”、“G”、“H”、“I”、“J”、“K”、“L”、“M”、“N”};
File[]Externaldrives=新文件[letters.length];
boolean[]FoundDrive=新的boolean[letters.length];
//初始化文件对象和初始驱动器状态
对于(int i=0;i