java entry的用法_Java ZipEntry setComment()用法及代码示例

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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值