ZipFile getComment() function in Java with examples
Last Updated :
06 Mar, 2019
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.
import java.util.zip.*;
public class solution {
public static void main(String args[])
{
try {
ZipFile zip_file
= new ZipFile( "f:\\file.zip" );
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().
import java.util.zip.*;
public class solution {
public static void main(String args[])
{
try {
ZipFile zip_file
= new ZipFile( "f:\\file.zip" );
zip_file.close();
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()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...