When nesting with multiple streams is used, it is always customary to turn off each stream from the inside out.
Today just know, when superfluous, only need to close the outermost layer of the mouth = flow on the line.
Like what:
FileWriter fileWritter1 = new FileWriter (OUTFILE1);
BufferedWriter bw1 = new BufferedWriter (fileWritter1);
Close only need to close the filewritter on it:
Filewritter1.close ();
The reason is in BufferedWriter source code, this is the BufferedWriter close () method source code:
This out object is however a writer:
This writer is precisely the writer that is passed in the BufferedWriter construction parameters, that is, the filewriter in this example. So when you close BufferedWriter,
In fact, nothing has been done, just simply call the FileWriter close () method. And the BufferedWriter Close () method is also a
Synchronized method. It can also cause efficiency problems in multi-threaded situations. So when you nest a multi-layer stream, you just need to close the outermost stream.