• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Efficient way of writing to file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a batch process that writes an output of 155 MB file to disk. When I observed the progress, it looks like it takes 10 minutes to write first 10 MB, about 20 minutes for the next 10 MB and so on. I used
Writer out = new PrintWriter(new BufferedWriter(new File Writer(fileName)), true);//true for auto flush
out.write(String);

Is this the most efficient way of writing or is it better to split the output to different files and merge all the files at the end? Are there more efficient ways of writing to file? I need suggestions.
Thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can write a 188 meg file in around 20 seconds with a Pentium 4 1.8Ghz, so I'd say your problem is probably your batch process. Are you maxing out the CPU or RAM? Check your task manager or run top and see if your process or others running on the same machine are hogging resources. Tweaking your java code won't do a thing unless you have the hardware to run it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic