Open
Description
feature(特征):
["stack_regex":"ObjectOutputStream","problem_type":"io_small_buffer"]
description(解决方案描述)
配合BufferedOutputStream使用
verify(验证结果)
compare | ObjectOutputStream | ObjectOutputStream+ByteArrayOutputStream |
---|---|---|
I/O time | 499 | 1 |
I/O cost time | 162.8ms | 87.3ms |
code(代码)
ByteArrayOutputStream bos = null;
ObjectOutputStream oos = null;
FileOutputStream fos = null;
try{
bos = new ByteArrayOutputStream(4096);
oos = new ObjectOutputStream(bos);
oos.writeObject();
oos.flush();
fos = new FileOutputStream(file);
bos.writeTo(fos);
bos.flush();
}
catch(Exception ex) {
ex.printStack()
}
finally {
if (oos != null) {
oos.close();
}
if (bos != null) {
bos.close();
}
if (fos != null) {
fos.close();
}
}