我有一个ByteArrayInputStream格式的图像。我想把它保存到我的文件系统中的某个位置。
我一直在兜圈子,你能帮帮我吗?
发布于 2010-05-13 14:19:46
如果你已经在使用Apache commons-io,你可以使用:
IOUtils.copy(byteArrayInputStream, new FileOutputStream(outputFileName));发布于 2010-05-13 14:00:02
InputStream in = //your ByteArrayInputStream here
OutputStream out = new FileOutputStream("filename.jpg");
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();发布于 2010-05-13 13:59:42
您可以使用以下代码:
ByteArrayInputStream input = getInputStream();
FileOutputStream output = new FileOutputStream(outputFilename);
int DEFAULT_BUFFER_SIZE = 1024;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
long count = 0;
int n = 0;
n = input.read(buffer, 0, DEFAULT_BUFFER_SIZE);
while (n >= 0) {
output.write(buffer, 0, n);
n = input.read(buffer, 0, DEFAULT_BUFFER_SIZE);
}https://stackoverflow.com/questions/2824674
复制相似问题