org.jiucai.appframework.common.deflater.zip
类 Zip

java.lang.Object
  继承者 org.jiucai.appframework.common.deflater.zip.Zip

public class Zip
extends Object

提供对单个文件与目录的压缩,并支持是否需要创建压缩源目录、中文路径

作者:
jzj

字段摘要
protected static Logs log
           
 
构造方法摘要
Zip()
           
 
方法摘要
static void doUncompressFile(String inFileName)
           
static String getFileName(String f)
           
static void main(String[] args)
           
static InputStream readFile(String archive, String filePath)
          读取压缩包中的指定文件
static void setEncoding(String charset)
          默认编码 UFT-8 设置为 UTF-8 时,压缩包的注释乱码,但可以正常使用 unzip / unzip2( Java API 标准解压缩) 类解压文件 设置为 GBK 时,压缩包的注释正常,只能是用 unzip 方法解压缩
static void unzip(String archive, String decompressDir)
          使用 org.apache.tools.zip.ZipFile 解压文件,它与 java 类库中的 java.util.zip.ZipFile 使用方式是一新的,只不过多了设置编码方式的 接口。
static void unzip2(String archive, String decompressDir)
          使用 java api 中的 ZipInputStream 类解压文件,但如果压缩时采用了 org.apache.tools.zip.ZipOutputStream时,而不是 java 类库中的 java.util.zip.ZipOutputStream时,该方法不能使用,原因就是编码方 式不一致导致,运行时会抛如下异常: java.lang.IllegalArgumentException at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:290) 当然,如果压缩包使用的是java类库的java.util.zip.ZipOutputStream 压缩而成是不会有问题的,但它不支持中文
static void zip(String src, String archive)
           
static void zip(String src, String archive, String comment)
          压缩文件夹或文件
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

log

protected static Logs log
构造方法详细信息

Zip

public Zip()
方法详细信息

setEncoding

public static void setEncoding(String charset)
默认编码 UFT-8 设置为 UTF-8 时,压缩包的注释乱码,但可以正常使用 unzip / unzip2( Java API 标准解压缩) 类解压文件 设置为 GBK 时,压缩包的注释正常,只能是用 unzip 方法解压缩

参数:
charset -

zip

public static void zip(String src,
                       String archive)
                throws FileNotFoundException,
                       IOException
抛出:
FileNotFoundException
IOException

zip

public static void zip(String src,
                       String archive,
                       String comment)
                throws FileNotFoundException,
                       IOException
压缩文件夹或文件

参数:
src -
archive -
comment - 压缩包注释
抛出:
FileNotFoundException
IOException

readFile

public static InputStream readFile(String archive,
                                   String filePath)
                            throws IOException
读取压缩包中的指定文件

参数:
archive - 压缩包文件
filePath - 指定的文件名
返回:
抛出:
IOException

unzip

public static void unzip(String archive,
                         String decompressDir)
                  throws IOException,
                         FileNotFoundException,
                         ZipException
使用 org.apache.tools.zip.ZipFile 解压文件,它与 java 类库中的 java.util.zip.ZipFile 使用方式是一新的,只不过多了设置编码方式的 接口。 注,apache 没有提供 ZipInputStream 类,所以只能使用它提供的ZipFile 来读取压缩文件。

参数:
archive - 压缩包路径
decompressDir - 解压路径
抛出:
IOException
FileNotFoundException
ZipException

doUncompressFile

public static void doUncompressFile(String inFileName)

getFileName

public static String getFileName(String f)

unzip2

public static void unzip2(String archive,
                          String decompressDir)
                   throws FileNotFoundException,
                          IOException
使用 java api 中的 ZipInputStream 类解压文件,但如果压缩时采用了 org.apache.tools.zip.ZipOutputStream时,而不是 java 类库中的 java.util.zip.ZipOutputStream时,该方法不能使用,原因就是编码方 式不一致导致,运行时会抛如下异常: java.lang.IllegalArgumentException at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:290) 当然,如果压缩包使用的是java类库的java.util.zip.ZipOutputStream 压缩而成是不会有问题的,但它不支持中文

参数:
archive - 压缩包路径
decompressDir - 解压路径
抛出:
FileNotFoundException
IOException

main

public static void main(String[] args)
                 throws Exception
参数:
args -
抛出:
IOException
Exception


Copyright © 2013. All Rights Reserved.