1、找到并打开apache/conf目录中的>直接通过工具类进行解压或者压缩文件即可。
import javaioBufferedInputStream;
import javaioBufferedOutputStream;
import javaioCloseable;
import javaioFile;
import javaioFileOutputStream;
import javaioIOException;
import javaioInputStream;
import javautilEnumeration;
import javautilzipZipEntry;
import javautilzipZipFile;
/
@author gdb
/
public class ZipUtilAll {
public static final int DEFAULT_BUFSIZE = 1024 16;
/
解压Zip文件
@param srcZipFile
@param destDir
@throws IOException
/
public static void unZip(File srcZipFile, String destDir) throws IOException
{
ZipFile zipFile = new ZipFile(srcZipFile);
unZip(zipFile, destDir);
}
/
解压Zip文件
@param srcZipFile
@param destDir
@throws IOException
/
public static void unZip(String srcZipFile, String destDir) throws IOException
{
ZipFile zipFile = new ZipFile(srcZipFile);
unZip(zipFile, destDir);
}
/
解压Zip文件
@param zipFile
@param destDir
@throws IOException
/
public static void unZip(ZipFile zipFile, String destDir) throws IOException
{
Enumeration< extends ZipEntry> entryEnum = zipFileentries();
ZipEntry entry = null;
while (entryEnumhasMoreElements()) {
entry = entryEnumnextElement();
File destFile = new File(destDir + entrygetName());
if (entryisDirectory()) {
destFilemkdirs();
}
else {
destFilegetParentFile()mkdirs();
InputStream eis = zipFilegetInputStream(entry);
Systemoutprintln(eisread());
write(eis, destFile);
}
}
}
/
将输入流中的数据写到指定文件
@param inputStream
@param destFile
/
public static void write(InputStream inputStream, File destFile) throws IOException
{
BufferedInputStream bufIs = null;
BufferedOutputStream bufOs = null;
try {
bufIs = new BufferedInputStream(inputStream);
bufOs = new BufferedOutputStream(new FileOutputStream(destFile));
byte[] buf = new byte[DEFAULT_BUFSIZE];
int len = 0;
while ((len = bufIsread(buf, 0, buflength)) > 0) {
bufOswrite(buf, 0, len);
}
} catch (IOException ex) {
throw ex;
} finally {
close(bufOs, bufIs);
}
}
/
安全关闭多个流
@param streams
/
public static void close(Closeable streams)
{
try {
for (Closeable s : streams) {
if (s != null)
sclose();
}
} catch (IOException ioe) {
ioeprintStackTrace(Systemerr);
}
}
/
@param args
@throws javalangException
/
public static void main(String[] args) throws Exception
{
// unZip(new File(ZipDemoclassgetResource("D:/123/HKRT-B2Bzip")toURI()), "D:/123/");
unZip("D:/123/123zip", "D:/123/");
// new File();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)