Java ZipFile getInputStream() function with examples
The getInputStream() function is a part of java.util.zip package. The function returns the InputStream of a specific ZipEntry passed as parameter.Closing the Zip File will also close all the InputStream generated by this function.
Function Signature :
public InputStream getInputStream(ZipEntry e)
Parameters : The function takes a ZipEntry object as parameter.
Return value : The function returns a InputStream Object to read the contents of the ZipFile Entry.
Below programs illustrates the use of getInputStream() function
Example 1: We will create a file named zip_file and get the zip file entry using getEntry() function and then get the Input Stream object to read the contents of the file.”file.zip” is a zip file present in f: directory.
Contents: This is a file in ZIP file.
Example 2: We will create a file named zip_file and get the zip file entry using getEntry() function and then get the Input Stream object to read the contents of the file.”file4.cpp” is not present in the zip file.
Error is thrown by the function.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.