我想使用 jmtp.jar 监视连接到我的 linux 操作系统的便携式设备。下面是我用来做同样事情的代码。它在 Windows 中运行良好,但是当我运行此代码时,它给了我“不支持的操作系统异常”。jmtp.jar 支持 linux 操作系统吗?如果没有,那么 Linux 操作系统的任何替代解决方案?
我使用的代码
import java.io.*;
import java.math.BigInteger;
import jmtp.PortableDevice;
import jmtp.PortableDeviceManager;
import jmtp.PortableDeviceObject;
import jmtp.PortableDeviceStorageObject;
public class Jmtp {
public static void main(String[] args) {
PortableDeviceManager manager = new PortableDeviceManager();
PortableDevice device = manager.getDevices()[0];
device.open();
System.out.println(device.getModel());
System.out.println("---------------");
// Iterate over deviceObjects
for (PortableDeviceObject object : device.getRootObjects()) {
// If the object is a storage object
if (object instanceof PortableDeviceStorageObject) {
PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;
for (PortableDeviceObject o2 : storage.getChildObjects()) {
System.out.println(o2.getOriginalFileName());
}
}
}
manager.getDevices()[0].close();
}
}
我得到的例外:
Exception in thread "main" java.lang.RuntimeException: not supported os
at jmtp.PortableDeviceManager.<init>(PortableDeviceManager.java:37)
at find_usb.Jmtp.main(Jmtp.java:24)