Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8425

Re: Creating a PrintWriter with BufferedWriter versus just File

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Creating a PrintWriter with BufferedWriter versus just File
Date Fri, 30 Sep 2011 12:55:50 -0700 (PDT)
Organization http://groups.google.com
Lines 24
Message-ID <2426537.1018.1317412551038.JavaMail.geo-discussion-forums@prho12> (permalink)
References <80d64f66-ad97-4b6e-8000-25c684ade081@p11g2000yqe.googlegroups.com>
Reply-To comp.lang.java.programmer@googlegroups.com
NNTP-Posting-Host 2620:0:1000:437c:224:d7ff:fe69:5838
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1317413531 26874 127.0.0.1 (30 Sep 2011 20:12:11 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Fri, 30 Sep 2011 20:12:11 +0000 (UTC)
In-Reply-To <80d64f66-ad97-4b6e-8000-25c684ade081@p11g2000yqe.googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=2620:0:1000:437c:224:d7ff:fe69:5838; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8425

Show key headers only | View raw


KevinSimonson wrote:
> What's the difference between this code:
> 
> PrintWriter destination
>           = new PrintWriter
>               ( new BufferedWriter( new FileWriter( new File( arg))));
> 
> and this code:
> 
> PrintWriter destination = new PrintWriter( new File( arg));
> 
> Do I get buffered output with the first code that I don't get with the
> second code?  Or do I get the same buffered behavior with both?

No, the write semantics differ between the two.  In the BufferedWriter version, writes to the underlying stream occur only when the BufferedWriter buffer fills.  With the second form, writes occur every time the PrintWriter writes.  There is nothing in the documentation of PrintWriter
<http://download.oracle.com/javase/7/docs/api/java/io/PrintWriter.html>
to indicate that it buffers writes.  So it seems unlikely that you would "get the same buffered behavior with both".

-- 
Lew

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Creating a PrintWriter with BufferedWriter versus just File KevinSimonson <kvnsmnsn@hotmail.com> - 2011-09-30 10:00 -0700
  Re: Creating a PrintWriter with BufferedWriter versus just File Lew <lewbloch@gmail.com> - 2011-09-30 12:55 -0700
  Re: Creating a PrintWriter with BufferedWriter versus just File Arne Vajhøj <arne@vajhoej.dk> - 2011-09-30 21:30 -0400
  Re: Creating a PrintWriter with BufferedWriter versus just File Roedy Green <see_website@mindprod.com.invalid> - 2011-10-01 05:06 -0700
    Re: Creating a PrintWriter with BufferedWriter versus just File Arne Vajhøj <arne@vajhoej.dk> - 2011-10-01 15:53 -0400

csiph-web