Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructing a PrintWriter object

 
Eric Gonzalez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jamal Hasanov
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic