Anand Sunderraman
Anand Sunderraman

Reputation: 8148

Java File Splitting

What will be the most eficient way to split a file in Java ? Like to get it grid ready...

(Edit) Modifying the question. Basically after scouring the net I understand that there are generally two methods followed for file splitting....

  1. Just split them by the number of bytes

    I guess the advantage of this method is that it is fast, but say I have all the data in a line and suppose the file split puts half the data in one split and the other half the data in another split, then what do I do ??

  2. Read them line by line

    This will keep my data intact, fine, but I suppose this ain't as fast as the above method

Upvotes: 1

Views: 2282

Answers (2)

Andreas Dolk
Andreas Dolk

Reputation: 114817

My first impression is that you have something like a comma separated value (csv) file. The usual way to read / parse those files is to

  • read them line by line
  • skip headers and empty lines
  • use String#split(String reg) to split a line into values (reg is chosen to match the delimiter)

Upvotes: 1

Andy Chase
Andy Chase

Reputation: 1368

Well, just read the file line by line and start saving it to a new file. Then when you decide it's time to split, start saving the lines to a new place.

Don't worry about efficiency too much unless it's a real problem later.

Upvotes: 3

Related Questions