Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #8419 > unrolled thread
| Started by | KevinSimonson <kvnsmnsn@hotmail.com> |
|---|---|
| First post | 2011-09-30 10:00 -0700 |
| Last post | 2011-10-01 15:53 -0400 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | KevinSimonson <kvnsmnsn@hotmail.com> |
|---|---|
| Date | 2011-09-30 10:00 -0700 |
| Subject | Creating a PrintWriter with BufferedWriter versus just File |
| Message-ID | <80d64f66-ad97-4b6e-8000-25c684ade081@p11g2000yqe.googlegroups.com> |
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?
Kevin Simonson
[toc] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-09-30 12:55 -0700 |
| Message-ID | <2426537.1018.1317412551038.JavaMail.geo-discussion-forums@prho12> |
| In reply to | #8419 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-09-30 21:30 -0400 |
| Message-ID | <4e866d3c$0$288$14726298@news.sunsite.dk> |
| In reply to | #8419 |
On 9/30/2011 1:00 PM, 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? You can lookup the classes in the Java docs. If the docs does not say that class XYZ does ABC, then you should not rely on class XYZ doing ABC even though a specific implementation may do it. Arne
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-10-01 05:06 -0700 |
| Message-ID | <5a0e87hunn6lhbtagtbsrdoeh1k51ufrt8@4ax.com> |
| In reply to | #8419 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-10-01 15:53 -0400 |
| Message-ID | <4e876fcb$0$293$14726298@news.sunsite.dk> |
| In reply to | #8438 |
On 10/1/2011 8:06 AM, Roedy Green wrote: > 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, 4?? More than 40! > you probably want to use 64K buffers, 64 KB buffer was not a problem when java.io was invented. Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web