aspose file tools*
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 Spring in Action this week in the Spring 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
Marshal

Joined: Mar 22, 2005
Posts: 42285
    
  64
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.


Ping & DNS - my free Android networking tools app
Shubham Semwal
Ranch Hand

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

Joined: Mar 22, 2005
Posts: 42285
    
  64
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: 3679
    
  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