2

Possible Duplicate:
Does closing the BufferedReader/PrintWriter close the socket connection?

My code is as following:

PrinterWriter pw = new PrinterWriter(new BufferedWriter(new
FileWriter("textfile.txt", true)));

pw.close();

Have I now properly closed PrinterWriter, BufferedWriter and FileWriter? Or have I just closed PrinterWriter?

Community
  • 1
  • 1
Lon
  • 23
  • 2

1 Answers1

1

Yes it is properly closed. Becouse the params are given ussing the keyword new. Otherwise you would also need to close the BufferWriter and the FileWriter(They will close automatically in this case). Always remember to close your streams when finishing working with them. Also the fact that the file is appendable(param true) does not affect to the rule.

javing
  • 12,307
  • 35
  • 138
  • 211