This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
 
subject: constructing a PrintWriter object
 
Similar Threads
File writing 1 line at a time
How to write XML to a new file.
Writing an Empty Line in a File....
tokenizer
e.printStackTrace();