public class Zip extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected static org.slf4j.Logger |
logger |
| 构造器和说明 |
|---|
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)
压缩文件夹或文件
|
public static void doUncompressFile(String inFileName)
public static InputStream readFile(String archive, String filePath) throws IOException
archive - 压缩包文件filePath - 指定的文件名IOException - IOExceptionpublic static void setEncoding(String charset)
charset - charsetpublic static void unzip(String archive, String decompressDir) throws IOException, FileNotFoundException, ZipException
archive - 压缩包路径decompressDir - 解压路径IOException - IOExceptionFileNotFoundException - FileNotFoundExceptionZipException - ZipExceptionpublic static void unzip2(String archive, String decompressDir) throws FileNotFoundException, IOException
archive - 压缩包路径decompressDir - 解压路径FileNotFoundException - FileNotFoundExceptionIOException - IOExceptionpublic static void zip(String src, String archive) throws FileNotFoundException, IOException
public static void zip(String src, String archive, String comment) throws FileNotFoundException, IOException
src - srcarchive - archivecomment - 压缩包注释FileNotFoundException - FileNotFoundExceptionIOException - IOExceptionCopyright © 2017 jiucai.org. All rights reserved.