gpt4 book ai didi

java - 如何从 USB pendrive 获取文件?

转载 作者:行者123 更新时间:2023-11-29 23:31:13 26 4
gpt4 key购买 nike

我在我的设备上添加了一个存储空间作为 USB 笔式驱动器,但我不知道如何从 USB 获取文件。

我试过了,但没用:

HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
HashMap<String, UsbDevice> usbDevices1 = new HashMap<>();
usbDevices1.clear();

if (!usbDevices.isEmpty()) {
boolean keep = true;
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
device = entry.getValue();
int deviceVID = device.getVendorId();
int devicePID = device.getProductId();
if (deviceVID == 1659 && devicePID == 8963) {
if (deviceVID != 0x1d6b && (devicePID != 0x0001 || devicePID != 0x0002 || devicePID != 0x0003)) {
// There is a device connected to our Android device. Try to open it as a Serial Port.
requestUserPermission();
keep = false;
} else {
connection = null;
device = null;
}

if (!keep)
break;
}
}
}

最佳答案

USB 闪存驱动器将是您手机上的外部存储设备,您可以使用以下方式从外部存储设备读取文件:

File path = context.getExternalFilesDir(null);

或者使用额外的库:

https://github.com/magnusja/libaums

关于java - 如何从 USB pendrive 获取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52640317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com