if (!"".equals(attachmentvo.getFilePath())) {
byte[] bytes1 = attachmentvo.getContexts();
ByteArrayInputStream bis = new ByteArrayInputStream(bytes1);
os = new FileOutputStream(outPath);
buffer = new byte[4096];
int len = 0;
while ((len = bis.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
buffer = null;
bis.close();
os.close();
}
byte[] bytes1 = attachmentvo.getContexts();
ByteArrayInputStream bis = new ByteArrayInputStream(bytes1);
os = new FileOutputStream(outPath);
buffer = new byte[4096];
int len = 0;
while ((len = bis.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
buffer = null;
bis.close();
os.close();
}
本文介绍了一种从内存中将文件下载到指定路径的方法。通过判断文件路径非空后,使用 ByteArrayInputStream 读取 byte 数组形式的数据,并将其写入由 FileOutputStream 打开的目标文件中,实现了文件的有效下载。
2239

被折叠的 条评论
为什么被折叠?



