aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes constructing a PrintWriter object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructing a PrintWriter object" Watch "constructing a PrintWriter object" New topic
Author

constructing a PrintWriter object

Eric Gonzalez
Greenhorn

Joined: May 01, 2002
Posts: 10
What are the difference between this to constructing ways? Which one I should use?
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(outputfile)));
PrintWriter pw = new PrintWriter(new FileOutputStream(outputfile), true);
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You should use whichever is appropriate for your application.
Actually, the first will probably solve most of your needs. You get buffering and use Writers which is usually a good idea.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
Hi, Eric
The main difference in constructor declaration is:
First declation calls
public PrintWriter(OutputStream out)constructor,
and another calls
PrintWriter(OutputStream out,boolean autoFlush ) constructor with autoFlush=true parameter.
And the difference is in autoFlush parameter value. (In first declaration it's false).
Jamal Hasanov
www.j-think.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructing a PrintWriter object