• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PrintWriter

 
Shubham Semwal
Ranch Hand
Posts: 154
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does printwriter always truncates the existing file to 0 size before adding any new data ??
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the underlying Writer, if there is one. You can construct a PrintWriter from an existing Writer, and that Writer might be setup to append to an existing file, or not; see the javadocs of the FileWriter constructors.
 
Shubham Semwal
Ranch Hand
Posts: 154
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and when there is no underlying writer ?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's easy to test, is it not? :-)
 
Shubham Semwal
Ranch Hand
Posts: 154
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is overwriting but nothing is written in PrintWriter class so i thought of clarifying here
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:Yes it is overwriting but nothing is written in PrintWriter class so i thought of clarifying here

Really ?
In the Javadoc for every constructor that doesn't have an underlying stream/writer it says
If the file exists then it will be truncated to zero size; otherwise, a new file will be created.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic