user710818
user710818

Reputation: 24248

Java BufferedWriter performance

I need to create large test files—near 3 GB. So I try to write for start only string "1"—to check performance and correctness.

FileWriter fstream = new FileWriter("c:/out.txt");
BufferedWriter out = new BufferedWriter(fstream,10000000);
for (int i = 0; i < 1000000000; i++) {
  //out.write(Integer.toString(1));
  out.write("1");
  out.newLine();
}
out.close();

In future versions I need to write random integers. Now it takes on my computer 3 min 26 s. Changing size of buffere seems doesn't help. Is it possible to accelerate process of writing? Thanks.

Upvotes: 1

Views: 1897

Answers (2)

Milhous
Milhous

Reputation: 14643

You may want to look at a raid array in order to speed up your writes. Writing a lot of data is a slow process. Also you can look at an SSD or in some in memory methods (ram drive).

Upvotes: 1

Mark Segal
Mark Segal

Reputation: 5550

Well, 3GB is 3072MB - and if you have a writing speed of 25MBps - it should take a bit longer then 2 minutes. Try it on a different computer and compare results - maybe its just you hard drive that isn't fast

Upvotes: 4

Related Questions