ZipFile getComment() function in Java with examples
The getComment() function is a part of java.util.zip package. The function returns a string which is the comment of the zip file.
Function Signature:
public String getComment()
Syntax:
zip_file.getComment();
Parameters: The function does not require any parameters
Return value: The function returns a String, which is the comment of the zip file
Exceptions: The function throws IllegalStateException if the zip file has been closed
Below programs illustrates the use of getComment() function
Example 1: Create a file named zip_file and get the comment using getComment() function.”file.zip” is a zip file present in f: directory.
// Java program to demonstrate the // use of getComment() function import java.util.zip.*; public class solution { public static void main(String args[]) { try { // Create a Zip File ZipFile zip_file = new ZipFile("f:\\file.zip"); // Display the comment // of the zip file // using getComment() function System.out.println("comment = " + zip_file.getComment()); } catch (Exception e) { System.out.println(e.getMessage()); } } } |
Output:
comment = This is a zip file comment
Example 2: Create a file named zip_file and get the comment using getComment() function. This function throws exception if we close the file and then call the function getComment().
// Java program to demonstrate the // use of getComment() function import java.util.zip.*; public class solution { public static void main(String args[]) { try { // Create a Zip File ZipFile zip_file = new ZipFile("f:\\file.zip"); // close the file zip_file.close(); // Display the comment // of the zip file // using getComment() function System.out.println("comment = " + zip_file.getComment()); } catch (Exception e) { System.out.println(e.getMessage()); } } } |
Output:
zip file closed
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipFile.html#getComment()
Recommended Posts:
- Java ZipEntry getComment() function with examples
- ZipFile getName() function in Java with examples
- ZipFile getEntry() function in Java with examples
- ZipFile size() function in Java with examples
- Java ZipFile getInputStream() function with examples
- ZipFile entries() function in Java with examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java SQL Timestamp before() function with examples
- Function Interface in Java with Examples
- Java SQL Timestamp after() function with examples
- Java ZipEntry setCompressedSize() function with examples
- Java ZipEntry getCreationTime() function with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


