setComment()函数是java.util.zip软件包的一部分。该函数将特定ZipEntry的Comment设置为指定的字符串。注释的最大长度为0xffff,如果字符串的长度大于0xffff,则将考虑前0xffff个字符。函数签名:
public void setComment(String s)
用法:
zip_entry.setComment(s);
参数:该函数接受String对象作为参数。
返回值:该函数不返回任何值。
Exceptions:该函数不会引发任何异常。
以下示例程序旨在说明setComment()函数的使用
范例1:我们将创建一个名为zip_file的文件,并使用getEntry()函数获取zip文件条目,然后设置指定ZipEntry的注释。“ file.zip”是f:目录中的一个zip文件。
// Java program to demonstrate the
// use of setComment() function
import java.util.zip.*;
import java.util.Enumeration;
import java.util.*;
import java.io.*;
public class solution {
public static void main(String args[])
{
try {
// Create a Zip File
ZipFile zip_file = new ZipFile("f:\\file1.zip");
// get the Zip Entry using
// the getEntry() function
ZipEntry entry = zip_file.getEntry("file.zip");
// get the Comment
// using the getComment()
// function
entry.setComment("This is a ZipEntry comment");
// get the Comment
// using the getComment()
// function
String input = entry.getComment();
// Display the comment
System.out.println("Comment:" + input);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
输出:
Comment:This is a Zip Entry comment)