Yes, Scot is correct. Without buffering, each invocation of a write() method would cause characters to be converted into bytes that would then be written immediately to the file. This can be very inefficient (see javadoc of BufferedWriter).

To further increase performance use un-synchronized io classes (unless of course, you have multiple threads are writing to the same file). Synchronized methods and synchronized statement blocks statement blocks are typically three (3) times slower than un-synchronized ones (according the a recent article in the Java Developer's Journal). The *OutputStream classes are unsychronized. Here is an example of how to setup one:

         // Create a buffered output stream for the file
         FileOutputStream fos = new FileOutputStream(filename);
         BufferedOutputStream bos = new BufferedOutputStream(fos);

Hope this helps,
Tom



-----Original Message-----
From: Abhilash Nair [
mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 21, 2002 8:48 AM
To: JDJList
Subject: [jdjlist] RE: Java IO Question


Yes Scot. I meant quickest to execute...
I've used StringBufferInputStream to read the data
from a StringBuffer and a FileWriter to write it on to
a text file to be stored in the local drive. Will
substituting BufferedWriter in place of a FileWriter
help the performance? Thanks for your suggestion.

Regards,
Abhi

--- Scot Mcphee <[EMAIL PROTECTED]> wrote:
> When you say quickest, do you mean quickest to code
> or quickest to execute?
> If you want quickest to execute I would use a
> BufferedWriter. Actually I'd
> use a BufferedWriter anyway.
>
> regs
> scot.
>
> > -----Original Message-----
> > From: Abhilash Nair [
mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, 21 August 2002 03:50
> > To: JDJList
> > Subject: [jdjlist] Java IO Question
> >
> >
> > Hi All:
> >
> > Could anyone please suggest the fastest and most
> > efficient way to transfer data from a StringBuffer
> to
> > a text file in the local drive?
> >
> > Thanks in Advance
> > Abhi
> >
> > =====
> > You can reach me on:
> > Weekdays: (617)509-5312
> > Weekends and evenings: (781)321-2065
> > Pager: (781)553-8323
> > Thanks and Regards,
> > Nair Abhilash R
> > (Abhi)
> >
> > __________________________________________________
> > Do You Yahoo!?
> > HotJobs - Search Thousands of New Jobs
> >
http://www.hotjobs.com
> >
> > To change your membership options, refer to:
> >
http://www.sys-con.com/java/list.cfm
> >
>
>
> To change your membership options, refer to:
>
http://www.sys-con.com/java/list.cfm


=====
You can reach me on:
Weekdays: (617)509-5312
Weekends and evenings: (781)321-2065
Pager: (781)553-8323
Thanks and Regards,
Nair Abhilash R
(Abhi)

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

THIS TRANSMISSION, INCLUDING ANY ATTACHMENTS OR FILES,

CONTAINS AIRNET COMMUNICATIONS CORPORATION CONFIDENTIAL

AND PROPRIETARY INFORMATION WHICH MAY BE OTHERWISE EXEMPT

FROM DISCLOSURE.

The information is intended to be for the exclusive use of the individual

or entity named above. If you are not the intended recipient,

be advised that any disclosure, copying, distribution or other use

of this information is strictly prohibited. If you have received this

transmission in error, please notify us by telephone at 1-321-984-1990 or

by email to [EMAIL PROTECTED] immediately and do not read, print

or save this information in any manner.

Reply via email to