-4

I am currently zipping a file and uploading to the disk. But before saving on the disk, I need to unzip the file and save the unzipped file on the disk. I have the filePath and fileInputStream available for me. Can anyone help me how I could achieve in unzipping a file before saving to the disk

FAZ
  • 255
  • 1
  • 3
  • 13
  • Are you sure your first sentence is correct? because if so, don't zip the file to begin with? Oh, and "uploading to the disk" makes no sense, if you say "the disk" people will assume it's local, and then you can only download toward it, not upload. – Aaron Jun 04 '16 at 16:59
  • I am uplodaing it from client to server (disk). So I need to zip and upload and in server side, I need to unzip and save – FAZ Jun 04 '16 at 17:02
  • What have you tried? If you're zipping already, that means you can read files from the file system and zip them. The reverse operation should thus not be difficult. – JB Nizet Jun 04 '16 at 17:05
  • 1
    Could you please have a look at: http://stackoverflow.com/questions/37564863/decompress-zip-file-with-java/37566068#37566068 – Sanjeev Saha Jun 04 '16 at 17:39
  • I can compress an 4gb-empty file to 1kb zip-file. You really do not like me to crash your system! – Grim Jun 04 '16 at 18:46

1 Answers1

1

Create a ZipInputStream from your fileInputStream, then browse its entries with .getNextEntry().
For each entry, check if it's a directory or a file. If it's a directory you might want to create it, if it's a file use the ZipInputStream's read method to read the content of the file into a byte[], which you'll have to write to the disk with a FileOutputStream.

Aaron
  • 24,009
  • 2
  • 33
  • 57