Closing an outermost stream object in Java -
when write this:
bufferedreader br = new bufferedreader(new inputstreamreader(new fileinputstream("c:\\test.txt"))); br.close(); closing outermost object, in case br, automatically close chained objects too.
but if there's still reference chained object?
something this:
fileinputstream fis = new fileinputstream("c:\\test.txt"); bufferedreader br = new bufferedreader(new inputstreamreader(fis)); br.close(); in case, don't want fis released, because need use in other stream soon.
so okay call br's close() here, , still can use fis?
so okay call br's close() here, , still can use fis?
no!
once br has wrapped fis, fis should not used other purpose because br has made assumption fis , alone wishes. could, example, pre-buffer or of fis during construction among many other things.
using fis other br uses not give unpredictable results interfere br's functionality significantly.
even if close br after creating it quite reasonable fis @ least part-consumed if not consumed - supposed closed.
Comments
Post a Comment