【发布时间】:2017-07-26 14:10:45
【问题描述】:
我正在使用libaums 库将一些文件写入 USB 设备:
private class CopyToUsbTask extends AsyncTask<CopyToUsbTaskParam, Integer, Void> {
List<CopyToUsbTaskParam.SingleToUsbParam> paramList;
private CopyToUsbTaskParam.SingleToUsbParam param;
public CopyToUsbTask() {
Log.e(TAG, "CopyToUsbTask: Constructor");
}
@Override
protected Void doInBackground(CopyToUsbTaskParam... params) {
paramList = params[0].paramList;
while(!paramList.isEmpty() ){
param = paramList.remove(0);
long time = System.currentTimeMillis();
queryUriMetaData(param.from);
try {
UsbFile root = currentFs.getRootDirectory();
UsbFile dirTo = null;
for(UsbFile usbFile : root.listFiles()){
if(usbFile.getName().endsWith(param.toDir)){
dirTo = usbFile;
}
}
UsbFile file = dirTo.createFile(param.name);
InputStream inputStream = activity.getContentResolver().openInputStream(param.from);
OutputStream outputStream = UsbFileStreamFactory.createBufferedOutputStream(file, currentFs);
byte[] bytes = new byte[1337];
int count;
long total = 0;
while ((count = inputStream.read(bytes)) != -1){
outputStream.write(bytes, 0, count);
}
outputStream.close();
inputStream.close();
file.close();
} catch (IOException e) {
Log.e(TAG, "error copying!", e);
}
Log.e(TAG, "copy time: " + (System.currentTimeMillis() - time));
}return null;
}
@Override
protected void onPostExecute(Void result) {
int mid = Integer.valueOf(param.name.split("_")[0]);
Log.e(TAG, "onPostExecute, mid= " + mid);
Helper.deleteBookOrder(mid);
}
}
有时(尤其是当 paramList.size() > 1 时)我会收到如下错误消息:
java.io.IOException: 无法写入设备,结果 == -1 errno 88 非套接字上的套接字操作
找不到此错误消息的含义。 感谢您的帮助!
【问题讨论】: