java如何解压页面上传到服务器的zip文件

java如何解压页面上传到服务器的zip文件,第1张

直接通过工具类进行解压或者压缩文件即可。
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();
}
}

我试了一下,没有问题
先问一下,你用的JDK是什么版 本。我是16_20,直接用你的程序。
zipFile = new ZipFile(new File(zipfile),"GBK");
Enumeration enumeration = zipFilegetEntries();
是报错的。
我改成了
zipFile = new ZipFile(new File(zipfile));
Enumeration enumeration = zipFileentries();
这应该不是主要问题。
有没有可能是你的压缩包损坏了。或是包里的那个文件坏了,跟一下断点,看一下是解那个文件出的错。

用UC下载Jad文件,然后改后缀安装。譬如_Jad下载后退出UC改成jad就可以安装。Jad只是证书或者引导文件utf-8的编码。必须配合Jar一起改后缀安装才能用。非智能诺基亚S40手机解压ZIP文件推荐下载MC41飞度证书版以及Blue
FTP170官方证书版。解压rar文件推荐无心,流年似水或者UniFM14泥人汉化版…


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13194623.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-18
下一篇 2023-06-18

发表评论

登录后才能评论

评论列表(0条)

保存