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


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

Re: Creating a PrintWriter with BufferedWriter versus just File

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Creating a PrintWriter with BufferedWriter versus just File
Date 2011-10-01 05:06 -0700
Organization Canadian Mind Products
Message-ID <5a0e87hunn6lhbtagtbsrdoeh1k51ufrt8@4ax.com> (permalink)
References <80d64f66-ad97-4b6e-8000-25c684ade081@p11g2000yqe.googlegroups.com>

Show all headers | View raw


On Fri, 30 Sep 2011 10:00:55 -0700 (PDT), KevinSimonson
<kvnsmnsn@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>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?

You don't get buffering, or at least significant buffering. Given that
computers have at least four times as much RAM as they had when Java
io was conceived, you probably want to use 64K buffers, or read the
whole file in one fell swoop, when the file does not stay open.
see http://mindprod.com/products1.html#HUNKIO

See http://mindprod.com/applet/fileio.html
to generate you sample code for Java I/O.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to 
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

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


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