Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.util.zip.ZipEntry;
  6. import java.util.zip.ZipInputStream;
  7.  
  8. public class ExtractFileFromZipFile {
  9.  
  10. public static void main(String args[])
  11. {
  12.  
  13. String sourceZipFile = "C:/FileIO/sourceFile.zip";
  14.  
  15. try
  16. {
  17. //create FileInputStream from the source zip file
  18. FileInputStream fin = new FileInputStream(sourceZipFile);
  19.  
  20. //create ZipInputStream from FileInputStream object
  21. ZipInputStream zin = new ZipInputStream(fin);
  22.  
  23. //get the first entry from the source zip file
  24. ZipEntry entry = zin.getNextEntry();
  25.  
  26. //crate OutputStream to extract the entry from zip file
  27. OutputStream os = new FileOutputStream("c:/extractedFile.css");
  28.  
  29.  
  30. byte[] buffer = new byte[1024];
  31. int length;
  32.  
  33. //read the entry from zip file and extract it to disk
  34. while( (length = zin.read(buffer)) > 0)
  35. {
  36. os.write(buffer, 0, length);
  37. }
  38.  
  39. //close the streams
  40. os.close();
  41.  
  42. //close the zip file
  43. zin.close();
  44.  
  45. System.out.println("File Extracted from zip file");
  46. }
  47. catch(IOException e)
  48. {
  49. System.out.println("IOException :" + e);
  50. }
  51.  
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement