Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

newBufferWriter  RSS feed

 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Couldn't figure out, why it doesn't write anything in file ?
 
K. Tsang
Bartender
Posts: 3624
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't flush the output so the file is empty.
 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:You didn't flush the output so the file is empty.



But now without flushing it is writing, why ?, i know only that try with resources automatically close the resources, but does it call flush also ?
 
Tony Docherty
Bartender
Posts: 3198
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also didn't close the stream which you should always do and you should do it in a finally clause to make sure it happens even if an exception is thrown.
 
K. Tsang
Bartender
Posts: 3624
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my understanding, the "write" part is putting the content into memory. The "flush" part is putting the content into the file or physical storage.

 
Tony Docherty
Bartender
Posts: 3198
78
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But now without flushing it is writing, why ?, i know only that try with resources automatically close the resources, but does it call flush also ?

Yes, closing a stream, flushes it before closing it.
 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!