Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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


Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
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: 42954
    
  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: 42954
    
  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