我正在创建一个java应用程序,用于检测系统连接设备的列表。当我运行应用程序时,它没有显示任何连接的设备...这是我的java代码请帮我工作这个
package com.mqs.lakshman;
import java.io.File;
import javax.swing.filechooser.FileSystemView;
public class Usbactivity
{
static String driveLetter="";
static FileSystemView fsv = FileSystemView.getFileSystemView();
public static void main(String[] args)
{
File[] f = File.listRoots();
for (int i = 0; i < f.length; i++) {
String drive = f[i].getPath();
String displayName = fsv.getSystemDisplayName(f[i]);
String type = fsv.getSystemTypeDescription(f[i]);
boolean isDrive = fsv.isDrive(f[i]);
boolean isFloppy = fsv.isFloppyDrive(f[i]);
boolean canRead = f[i].canRead();
boolean canWrite = f[i].canWrite();
if (canRead && canWrite && !isFloppy && isDrive && (type.toLowerCase().contains("removable") || type.toLowerCase().contains("rimovibile")))
{
System.out.println("Detected PEN Drive: " + drive + " - "+ displayName);
driveLetter = drive;
break;
}
}
if (driveLetter.equals(""))
{
}
else
{
}
}
}