JAVAutil。拉链Java中的ZipEntry类

此类用于表示ZIP文件条目。 建设者

null
  • ZipEntry(字符串名称): 使用指定的名称创建新的zip条目。
  • ZipEntry(ZipEntry e): 创建一个新的zip条目,其中的字段取自指定的zip条目。

方法:

  • 对象克隆(): 返回此条目的副本。
    Syntax :public Object clone()
    Overrides:
    clone in class Object
    Returns:
    a clone of this instance.
  • 字符串getComment(): 返回条目的注释字符串,如果没有,则返回null。
    Syntax :public String getComment()
    Returns:
    the comment string for the entry, or null if none
  • long getCompressedSize(): 返回压缩条目数据的大小,如果未知,返回-1。对于存储的条目,压缩大小将与条目的未压缩大小相同。
    Syntax :public long getCompressedSize()
    Returns:
    the size of the compressed entry data, or -1 if not known
  • long getCrc(): 返回未压缩项数据的CRC-32校验和,如果未知,返回-1。
    Syntax :public long getCrc()
    Returns:
    the CRC-32 checksum of the uncompressed entry data, or -1 if not known
  • 字节[]getExtra(): 返回条目的额外字段数据,如果没有,则返回null。
    Syntax :=public byte[] getExtra()
    Returns:
    the extra field data for the entry, or null if none
    
  • int getMethod(): 返回条目的压缩方法,如果未指定,则返回-1。
    Syntax :public int getMethod()
    Returns:
    the compression method of the entry, or -1 if not specified
  • 字符串getName(): 返回条目的名称。
    Syntax :public String getName()
    Returns:
    the name of the entry
    
  • long getSize(): 返回输入数据的未压缩大小,如果未知,返回-1。
    Syntax :public long getSize()
    Returns:
    the uncompressed size of the entry data, or -1 if not know
  • long getTime(): 返回条目的修改时间,如果未指定,则返回-1。
    Syntax :public long getTime()
    Returns:
    the modification time of the entry, or -1 if not specified
  • int hashCode(): 返回此项的哈希代码值。
    Syntax :public int hashCode()
    Overrides:
    hashCode in class Object
    Returns:
    a hash code value for this object.
  • 布尔isDirectory(): 如果这是目录项,则返回true。目录条目定义为名称以“/”结尾的条目。
    Syntax :public boolean isDirectory()
    Returns:
    true if this is a directory entry
  • void setComment(字符串注释): 设置条目的可选注释字符串。ZIP条目注释的最大长度为0xffff。如果编码后指定注释字符串的长度大于0xFFFF字节,则仅将前0xFFFF字节输出到ZIP文件条目。
    Syntax :public void setComment(String comment)
    Parameters:
    comment - the comment string
  • 无效设置压缩大小(长csize): 设置压缩条目数据的大小。
    Syntax :public void setCompressedSize(long csize)
    Parameters:
    csize - the compressed size to set to
  • 无效设置crc(长crc): 设置未压缩条目数据的CRC-32校验和。
    Syntax :public void setCrc(long crc)
    Parameters:
    crc - the CRC-32 value
    Throws:
    IllegalArgumentException
  • void setExtra(字节[]额外): 为条目设置可选的额外字段数据。
    Syntax :public void setExtra(byte[] extra)
    Parameters:
    extra - the extra field data bytes
    Throws:
    IllegalArgumentException
  • void setMethod(int方法): 设置条目的压缩方法。
    Syntax :public void setMethod(int method)
    Parameters:
    method - the compression method, either STORED or DEFLATED
    Throws:
    IllegalArgumentException 
  • void setSize(长尺寸): 设置输入数据的未压缩大小。
    Syntax :public void setSize(long size)
    Parameters:
    size - the uncompressed size in bytes
    Throws:
    IllegalArgumentException 
  • 无效设置时间(长时间): 设置条目的修改时间。
    Syntax :public void setTime(long time)
    Parameters:
    time - the entry modification time in number of milliseconds since the epoch
  • 字符串toString(): 返回ZIP条目的字符串表示形式。
    Syntax :public String toString()
    Overrides:
    toString in class Object
    Returns:
    a string representation of the object.

节目:

//Java program demonstrating ZipEntry methods
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
class ZipEntryDemo
{
public static void main(String[] args) throws IOException
{
FileInputStream fis = new FileInputStream( "Awesome CV.zip" );
ZipInputStream jis = new ZipInputStream(fis);
PrintStream cout=System.out;
//reading the next ZIP file entry
ZipEntry ze = jis.getNextEntry();
//illustrating getName()
cout.println(ze.getName());
//illustrating getComment()
ze.setComment( "This is a comment" );
cout.println(ze.getComment());
//illustrating setCompressedSize() and getCompressedSize()
ze.setCompressedSize(23l);
cout.println( "CompressedSize of the entry = " + ze.getCompressedSize());
//illustrating getSize() and setSize()
ze.setSize(53l);
cout.println( "Size = " + ze.getSize());
//illustrating getCrc() and setCrc()
ze.setCrc( 01 );
cout.println(ze.getCrc());
//illustrating getMethod and setMethod
ze.setMethod(ZipEntry.STORED);
cout.println(ze.getMethod());
//illustrating getCreation and setCreation()
ze.setCreationTime(FileTime.from( 10000 , TimeUnit.DAYS));
cout.println(ze.getCreationTime());
//illustrating getLastAccessTime and setLastAccessTime
ze.setLastAccessTime(FileTime.from( 1000 ,TimeUnit.DAYS));
cout.println(ze.getLastAccessTime());
//illustrating clone()
ZipEntry zeclone = (ZipEntry) ze.clone();
cout.println(zeclone.getName());
//illustrating isDirectory
cout.println(ze.isDirectory());
//illustrating hashcode()
cout.println( "hashcode = " + ze.hashCode());
}
}


输出:

awesome-cv.cls
This is a comment
CompressedSize of the entry = 23
Size = 53
1
0
1997-05-19T00:00:00Z
1972-09-27T00:00:00Z
awesome-cv.cls
false
hashcode = 1687382489

本文由 尼森特·夏尔马 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享