getsize java_Java ZipEntry getSize()用法及代码示例
getSize()函數(shù)是java.util.zip軟件包的一部分。該函數(shù)返回作為參數(shù)傳遞的特定ZipEntry的未壓縮大小,如果未知則返回-1。函數(shù)簽名:
public long getSize()
用法:
zip_entry.getSize();
參數(shù):此功能不需要任何參數(shù)。
返回值:該函數(shù)返回一個long值,即此ZipEntry的未壓縮大小。
Exceptions:該函數(shù)不會引發(fā)任何異常。
以下示例程序旨在說明getSize()函數(shù)的使用
范例1:我們將創(chuàng)建一個名為zip_file的文件,并使用getEntry()函數(shù)獲取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:我們將創(chuàng)建一個名為zip_file的文件,并使用getEntry()函數(shù)獲取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
總結(jié)
以上是生活随笔為你收集整理的getsize java_Java ZipEntry getSize()用法及代码示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IDC:2022 年中国蓝牙耳机市场同比
- 下一篇: java robot 文档_文件配置 ·