• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting a zip file and rejoining it

 
shirish katti
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am developing an application into which i need to split a huge zip file into 4 to 5 parts and then rejoin it...

I have tried this with the code i have attached...

The splitting part works perfectly.. Even the re joining part works but the rejoined file is of 0kb with no content into it...

Any of you free then please execute this code snippet and let me know if you have any solution...

Thanks in Advance..
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lines 114 and 130 cause your loop to break off immediately. You're join method looks for files without the ".sp" extension. If you use line 111 instead of line 112 the program actually runs.

You may want to consider different ways of reading and writing though. Your split takes 6 seconds for a 801kB file with chunk size of 100kB. Your join of the same chunks then takes 301 seconds!

Instead of using RandomAccessFile, try using FileInputStream and FileOutputStream instead. Here's your join method with streams:
As you see, I only changed the RandomAccessFile references to use (File)OutputStream and (File)InputStream instead. I've gone down to 6 seconds for the join. You can perhaps even improve it a bit more by using buffering; simply change lines 9 and 17 from my code to these:
This is called stream chaining. With this buffering the join method now returns within a second, with the same results. I'm sure that using the same approach for the split method will have similar speed improvements.
 
shirish katti
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Thanks for your prompt reply...

Thanks for make it time efficient...

Lines 114 and 130 cause your loop to break off immediately. You're join method looks for files without the ".sp" extension. If you use line 111 instead of line 112 the program actually runs.


sorry for this actually i had used line 111 itself...

Even joining is working but the thing is the joined file shows as 0kb and when i use win zip to open it.. It opens and works fine only until i keep the source file i mean the original file in the same location if i delete the source file then it doesn't work properly..

In short it gets redirected to the source file.. Any idea..
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your output file remains as 0 bytes until your program closes because you never flush() your changes. Once you close the file it gets flushed automatically, and the file will have the proper size. But like I said, my measurements with just a small file already took me 5 minutes to join. I've also shown you how to improve that speed.
 
shirish katti
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

I have even tried it with flushing the file...

As per my knowledge flushing doesn't guarantees that the content is written to the physical disk...

I made this code time efficient, but the problem of output file of 0kb still remains the same..

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic