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


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

Re: Writing to file

Date 2011-12-02 19:58 -0500
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Writing to file
References <e1b7d157-4018-44a7-8176-3a2f308562b8@cu3g2000vbb.googlegroups.com>
Message-ID <4ed9744e$0$294$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source

Show all headers | View raw


On 11/30/2011 2:31 PM, sara wrote:
> I have a program which generates many lines of data where each line
> includes an integer and two floats. I want to know the fastest way to
> write these generated lines to a file. Currently, I am writing to a
> binary file as follows:
> FileOutputStream fos = new FileOutputStream(fileName);
> DataOutputStream dos = new DataOutputStream(fos);
> for (n : N) {
> dos.writeInt(n.id);
> dos.writeFloat(x.floatValue());
> dos.writeFloat(y.floatValue());
> }
>
> However it seems that this approach is very slow. Can I use any kind
> of buffering technique to speed up writing to binary file?

You can use a BufferedOutputStream between the DataOutputStream
and the FileOutputStream.

But I am a bit skeptical about the choice of format for
persisting data.

Arne

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


Thread

Writing to file sara <sarasara82@gmail.com> - 2011-11-30 11:31 -0800
  Re: Writing to file Lew <lewbloch@gmail.com> - 2011-11-30 14:20 -0800
  Re: Writing to file Roedy Green <see_website@mindprod.com.invalid> - 2011-12-02 01:33 -0800
  Re: Writing to file Arne Vajhøj <arne@vajhoej.dk> - 2011-12-02 19:58 -0500

csiph-web