tags:

views:

64

answers:

2

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

+2  A: 

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.

asperous.us
A: 

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)
Andreas_D
Well, unless the file has commas in it, that would become a problem
asperous.us
@asperous.us - the strategy works with any delimeter. A delimter char or sequence must not be substring of any value, but thats a usual condition for csv files.
Andreas_D
will it work even for unicorns? :)
willcodejavaforfood