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();
}
本文介绍了一个从内存中读取文件并将其写入指定路径的Java实现案例。通过使用ByteArrayInputStream和FileOutputStream,此代码段展示了如何将字节数组转换为文件的过程。此过程适用于从服务器获取文件内容并保存到本地的应用场景。
162

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



