SlideShare ist ein Scribd-Unternehmen logo
1 von 16
How to create a zip file for a set of files (Compress):
Step1: Create a set of files (contains images, documents, texts)
We will zip up the following files in this assignment:
1. file1.txt
2. file2.docx
3. file3.jpg (Image/file3.jpg)
4. file4.jpg (Image/file4.jpg)
5. file5.txt( Samiha/Tarin/Jannat/file5.txt)
The test class creates a FileOutputStream to 'atest.zip', the name of the zip file to create. It
creates a ZipOutputStream object based on the FileOutputStream. It then calls its addToZipFile()
method to write each file to the zip file.
In addToZipFile(), we create a FileInputStream to read from the specified file. We create a
ZipEntry object for the file and tell the ZipOutputStream that we'll be writing a ZipEntry to it via
the call to putNextEntry(). We read the file contents from the FileInputStream and write the file
contents to the ZipOutputStream.
Step2:
Test.java
Step3:
The execution of “test.java” is shown below in the Console view:
So, the atest.zip file has been created.
Step4:
If we examine the contents of atest.zip, we can see that the zip file that we created contains the
expected files.
file1.txt properties:
file2.docx properties:
file3.jpg properties:
file4.jpg properties:
file5.txt properties:
Uncompressing the createdZip file:
Zip compression can take a certain amount of time to perform. On occasion, you may want to
create a zip file to store multiple files in a single file, but you might want to avoid the time
required to compress the files. As an example, if you are zipping a set of large files that have
already been compressed, it would make sense to avoid compression in the big zip file that
you're creating. To demonstrate how to do this:
Step1:
Step2:
We used the test class to create a compressed zip file from a set of files. Now, we'll create an
'uncompressed-test.zip' file and add the following line to the test class:
test.java
Step3:
The execution of “test.java” is shown below in the Console view:
Step4:
The uncompressed-test.zip file was created. If we examine the contents of uncompressed-
test.zip, we can see that the zip file that we created contains the expected files.
file1.txt properties:
file2.docx properties:
file3.jpg properties:
file4.jpg:
file5.txt:
Unzip the contents of a zipped file:
How to extract the contents of a zip file using the java.util.zip package and a little basic
File/Stream Java code. The atest.zip file is the zip file that we will unzip, and ExtractZipContents
is the Java class that will extract the contents of the zip file and write them to the file system.
The ExtractZipContents class is shown below. It creates a ZipFile object based on atest.zip. It
then enumerates over the ZipEntry objects within the zip file. It displays the name, size, and
compressed size of each ZipEntry object. If the name of the ZipEntry ends with a slash, it is a
directory, and this directory gets created along with all other directories above it via
file.mkdirs(). The 'continue' skips the rest of the code in the while loop and lets the while loop go
to the next zip entry.
If the name doesn't end with a slash, then we check to see if the file created from the current
ZipEntry name has a parent file, which would be a directory. If it has a parent, the parent
directory is created along with any other higher directories via the file.mkdirs() call.
Following this, the ExtractZipContents class does some standard Java input stream/output stream
code to read the contents of the current ZipEntry object and write the contents to the file that was
created using the ZipEntry name.
Step2: ExtractZipContents.java
Step3:
The execution of our ExtractZipContents class with the atest.zip file is shown in the Console
view below:
We can see, using the java.util.zip package along with some standard Java file and stream code makes
it easy to extract the files within a zip file.

Weitere ähnliche Inhalte

Ähnlich wie file compression/zip file.report

ExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdf
aquacare2008
 
Uploadifyv2 1-0manual-100417052228-phpapp01
Uploadifyv2 1-0manual-100417052228-phpapp01Uploadifyv2 1-0manual-100417052228-phpapp01
Uploadifyv2 1-0manual-100417052228-phpapp01
Nut Jaya
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
sirmanohar
 

Ähnlich wie file compression/zip file.report (20)

ExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdf
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
Chapter10
Chapter10Chapter10
Chapter10
 
Zipnotes
ZipnotesZipnotes
Zipnotes
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
File handling
File handlingFile handling
File handling
 
Qtp launch
Qtp launchQtp launch
Qtp launch
 
FileHandling.docx
FileHandling.docxFileHandling.docx
FileHandling.docx
 
Java File I/O
Java File I/OJava File I/O
Java File I/O
 
Uploadifyv2 1-0manual-100417052228-phpapp01
Uploadifyv2 1-0manual-100417052228-phpapp01Uploadifyv2 1-0manual-100417052228-phpapp01
Uploadifyv2 1-0manual-100417052228-phpapp01
 
File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 
Linux basics
Linux basicsLinux basics
Linux basics
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
 

Mehr von Taslima Yasmin Tarin

Mehr von Taslima Yasmin Tarin (15)

Restaurant management system
Restaurant management systemRestaurant management system
Restaurant management system
 
RSA algorithem
RSA algorithemRSA algorithem
RSA algorithem
 
CDMA
CDMACDMA
CDMA
 
Mobile Satellite Communication
Mobile Satellite CommunicationMobile Satellite Communication
Mobile Satellite Communication
 
Application of DSP in Biomedical science
Application of DSP in Biomedical scienceApplication of DSP in Biomedical science
Application of DSP in Biomedical science
 
Real Life Application of Digital Electronics
Real Life Application of Digital ElectronicsReal Life Application of Digital Electronics
Real Life Application of Digital Electronics
 
GPS (Global Positioning System) application
GPS (Global Positioning System) applicationGPS (Global Positioning System) application
GPS (Global Positioning System) application
 
Artificial intelligence chatbot Report
Artificial intelligence chatbot ReportArtificial intelligence chatbot Report
Artificial intelligence chatbot Report
 
AI chatbot for massenger
AI chatbot for massengerAI chatbot for massenger
AI chatbot for massenger
 
file compression ,zip file
file compression ,zip filefile compression ,zip file
file compression ,zip file
 
Bangali
BangaliBangali
Bangali
 
oscillator
oscillatoroscillator
oscillator
 
farakka barrage
farakka barragefarakka barrage
farakka barrage
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Operation Amplifire
Operation AmplifireOperation Amplifire
Operation Amplifire
 

Kürzlich hochgeladen

In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
ahmedjiabur940
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
wsppdmt
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
gajnagarg
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
vexqp
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
Health
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
vexqp
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
q6pzkpark
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
wsppdmt
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
ranjankumarbehera14
 

Kürzlich hochgeladen (20)

In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATIONCapstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Switzerland Constitution 2002.pdf.........
Switzerland Constitution 2002.pdf.........Switzerland Constitution 2002.pdf.........
Switzerland Constitution 2002.pdf.........
 
SR-101-01012024-EN.docx Federal Constitution of the Swiss Confederation
SR-101-01012024-EN.docx  Federal Constitution  of the Swiss ConfederationSR-101-01012024-EN.docx  Federal Constitution  of the Swiss Confederation
SR-101-01012024-EN.docx Federal Constitution of the Swiss Confederation
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 

file compression/zip file.report

  • 1. How to create a zip file for a set of files (Compress): Step1: Create a set of files (contains images, documents, texts) We will zip up the following files in this assignment: 1. file1.txt 2. file2.docx 3. file3.jpg (Image/file3.jpg) 4. file4.jpg (Image/file4.jpg) 5. file5.txt( Samiha/Tarin/Jannat/file5.txt)
  • 2. The test class creates a FileOutputStream to 'atest.zip', the name of the zip file to create. It creates a ZipOutputStream object based on the FileOutputStream. It then calls its addToZipFile() method to write each file to the zip file. In addToZipFile(), we create a FileInputStream to read from the specified file. We create a ZipEntry object for the file and tell the ZipOutputStream that we'll be writing a ZipEntry to it via the call to putNextEntry(). We read the file contents from the FileInputStream and write the file contents to the ZipOutputStream. Step2: Test.java
  • 3.
  • 4. Step3: The execution of “test.java” is shown below in the Console view: So, the atest.zip file has been created. Step4: If we examine the contents of atest.zip, we can see that the zip file that we created contains the expected files.
  • 8. Uncompressing the createdZip file: Zip compression can take a certain amount of time to perform. On occasion, you may want to create a zip file to store multiple files in a single file, but you might want to avoid the time required to compress the files. As an example, if you are zipping a set of large files that have already been compressed, it would make sense to avoid compression in the big zip file that you're creating. To demonstrate how to do this: Step1:
  • 9. Step2: We used the test class to create a compressed zip file from a set of files. Now, we'll create an 'uncompressed-test.zip' file and add the following line to the test class: test.java
  • 10.
  • 11. Step3: The execution of “test.java” is shown below in the Console view: Step4: The uncompressed-test.zip file was created. If we examine the contents of uncompressed- test.zip, we can see that the zip file that we created contains the expected files.
  • 14. file5.txt: Unzip the contents of a zipped file: How to extract the contents of a zip file using the java.util.zip package and a little basic File/Stream Java code. The atest.zip file is the zip file that we will unzip, and ExtractZipContents is the Java class that will extract the contents of the zip file and write them to the file system. The ExtractZipContents class is shown below. It creates a ZipFile object based on atest.zip. It then enumerates over the ZipEntry objects within the zip file. It displays the name, size, and compressed size of each ZipEntry object. If the name of the ZipEntry ends with a slash, it is a directory, and this directory gets created along with all other directories above it via file.mkdirs(). The 'continue' skips the rest of the code in the while loop and lets the while loop go to the next zip entry. If the name doesn't end with a slash, then we check to see if the file created from the current ZipEntry name has a parent file, which would be a directory. If it has a parent, the parent directory is created along with any other higher directories via the file.mkdirs() call. Following this, the ExtractZipContents class does some standard Java input stream/output stream code to read the contents of the current ZipEntry object and write the contents to the file that was created using the ZipEntry name.
  • 16. Step3: The execution of our ExtractZipContents class with the atest.zip file is shown in the Console view below: We can see, using the java.util.zip package along with some standard Java file and stream code makes it easy to extract the files within a zip file.