enter image description here我尝试从流(网址响应)下载文件,但没有移动设备。但是某些移动设备无法工作,文件创建失败。 我正在更改字节[4096],字节[1024] ...,发生相同的错误 请给我任何建议
public void saveToDisk(ResponseBody body, String pdfFileName, String module_type, String test_name) {
try {
File sdcard_destinationFile;
if (module_type.equalsIgnoreCase("ADD")) {
sdcard_destinationFile = new File(Environment.getExternalStorageDirectory()
+ "/download/" + pdfFileName + "_" + test_name + ".pdf");
} else {
sdcard_destinationFile = new File(Environment.getExternalStorageDirectory()
+ "/download/" + pdfFileName + ".pdf");
}
InputStream is = null;
OutputStream os = null;
try {
Log.e("file",body+"");
is = body.byteStream();
os = new FileOutputStream(sdcard_destinationFile);
byte data[] = new byte[4096];
int count;
int progress = 0;
while ((count = is.read(data)) != -1) {
os.write(data, 0, count);
progress += count;
Log.d(TAG, "Progress: " + progress + "/" + body.contentLength() + " >>>> " + (float) progress / body.contentLength());
}
Log.d("aaaaa", "Progress: " + progress + "/" + body.contentLength() + " >>>> " + (float) progress / body.contentLength());
os.flush();
Log.e("isis",is +"");
Log.e("isis",os +"");
if (is != null) is.close();
if (os != null) os.close();
Log.d(TAG, "File saved successfully!");
showPdf(pdfFileName, module_type, test_name);
return;
} catch (IOException e) {
e.printStackTrace();
Log.d(TAG, "Failed to save the file!");
return;
} finally {
}
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "Failed to save the file!");
return;
}
}