• Post Reply Bookmark Topic Watch Topic
  • New Topic

newBufferWriter

 
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: 3610
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
Saloon Keeper
Posts: 3142
72
  • 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: 3610
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
Saloon Keeper
Posts: 3142
72
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!