getsize java_Java ZipEntry getSize()用法及代码示例

getSize()函数是java.util.zip软件包的一部分。该函数返回作为参数传递的特定ZipEntry的未压缩大小,如果未知则返回-1。函数签名:

public long getSize()

用法:

zip_entry.getSize();

参数:此功能不需要任何参数。

返回值:该函数返回一个long值,即此ZipEntry的未压缩大小。

Exceptions:该函数不会引发任何异常。

以下示例程序旨在说明getSize()函数的使用

范例1:我们将创建一个名为zip_file的文件,并使用getEntry()函数获取zip文件条目,然后获取指定ZipEntry的未压缩大小。“ file.zip”是f:目录中的一个zip文件。我们将以“.zip”文件作为ZipEntry

// Java program to demonstrate the

// use of getSize() 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 uncompressed Size

// using the getSize()

// function

long input = entry.getSize();

// Display the uncompressed Size

System.out.println("uncompressed Size:" + input);

}

catch (Exception e) {

System.out.println(e.getMessage());

}

}

}

输出:

uncompressed Size:2153

范例2:我们将创建一个名为zip_file的文件,并使用getEntry()函数获取zip文件条目,然后获取指定ZipEntry的未压缩大小。“ file.zip”是f:目录中的一个zip文件。我们将以“.cpp”文件作为ZipEntry

// Java program to demonstrate the

// use of getSize() 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("file1.cpp");

// Get the uncompressed Size

// using the getSize()

// function

long input = entry.getSize();

// Display the uncompressed Size

System.out.println("uncompressed Size:" + input);

}

catch (Exception e) {

System.out.println(e.getMessage());

}

}

}

输出:

uncompressed Size:783

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值