This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes PrintWriter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "PrintWriter" Watch "PrintWriter" New topic
Author

PrintWriter

Shubham Semwal
Ranch Hand

Joined: Mar 08, 2014
Posts: 62
Does printwriter always truncates the existing file to 0 size before adding any new data ??
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
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

Joined: Mar 08, 2014
Posts: 62
and when there is no underlying writer ?
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
That's easy to test, is it not? :-)
Shubham Semwal
Ranch Hand

Joined: Mar 08, 2014
Posts: 62
Yes it is overwriting but nothing is written in PrintWriter class so i thought of clarifying here
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
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.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PrintWriter
 
It's not a secret anymore!