aspose file tools*
The moose likes Java in General and the fly likes File splitting with Java..Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "File splitting with Java..Help" Watch "File splitting with Java..Help" New topic
Author

File splitting with Java..Help

preetha balakrishnan
Greenhorn

Joined: Jun 08, 2009
Posts: 2

i need to split a file into several files, each having the same header/trailer as the orignal file, but each file only having 450 lines(including header and trailer so 448 lines from the orignal file).
for ex if there are 900 lines in the original file, that would be 3 files,

file 1 with header/trailer from Original, and 1 to 448 lines from Original file.
file 2 with header/trailer from Original, and 449 to 898 lines from Original file.
file 3 with header/trailer from Original, and 898 to 900 lines from Original file.

Any help is appreciated.

Regards
Preetha
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Welcome to JavaRanch
We don't simply give out that sort of answer, but if you tell us what you have achieved we shall be happy to help. What have you managed so far? Since you have provided a good description of your requirement, you should be able to get some method together easily.
Pseudo-code might be better; it allows you to see what is happening more easily.
preetha balakrishnan
Greenhorn

Joined: Jun 08, 2009
Posts: 2
1) Read file -- Done
2) Count lines --> done
3) find header/ trailer --> done


i then get the total count of lines/divide by 450, round the value and decide how many files to create.

i can iterate over the number of files to create then for each one create a new file, add the contents of the array from 1 to 448 to each one then would like to remove them from the array.

Since i cannot remove them from the array..How do i do this..put it into an arrayList..?

BP
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

i can iterate over the number of files to create then for each one create a new file, add the contents of the array from 1 to 448 to each one then would like to remove them from the array.

Since i cannot remove them from the array..How do i do this..put it into an arrayList..?


Another optiion is to have your method -- that writes out the array -- be able to have the start and end specified. This way, you don't have to change (ie, delete items) while you doing this. Just adjust the start and end for each file being written.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
By "divide by 450" do you mean "divide by 448?" Remember the % operator which will allow you to tell whether there is a remainder, then you can add 1 to the number of files from lines / 448.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: File splitting with Java..Help