
正文
java解压文件的代码 java解压包
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java压缩文件用ZipInputStream无法解压,下面是源代码
我想代码基本没有错,可以解压zip文件
但你的输入文件是rar。
rar和zip是完全不同的算法。rar是商业压缩格式,zip是公开格式。
java的预置库目前无法直接解压rar ,需要用第三方库
相关问答
Q1: 代码压缩文件怎么去拖进java
将压缩文件解压到指定java解压文件的代码的文件夹中。代码压缩文件去拖进java将压缩文件解压到指定java解压文件的代码的文件夹中。Java是由SunMicrosystems公司于1995年5月推出java解压文件的代码的Java面向对象程序设计语言和Java平台的总称。
Q2: java如何解压页面上传到服务器的zip文件
直接通过工具类进行解压或者压缩文件即可。
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
*
* @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 = zipFile.entries();
ZipEntry entry = null;
while (entryEnum.hasMoreElements()) {
entry = entryEnum.nextElement();
File destFile = new File(destDir + entry.getName());
if (entry.isDirectory()) {
destFile.mkdirs();
}
else {
destFile.getParentFile().mkdirs();
InputStream eis = zipFile.getInputStream(entry);
System.out.println(eis.read());
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 = bufIs.read(buf, 0, buf.length)) 0) {
bufOs.write(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)
s.close();
}
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}
/**
* @param args
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception
{
// unZip(new File(ZipDemo.class.getResource("D:/123/HKRT-B2B.zip").toURI()), "D:/123/");
unZip("D:/123/123.zip", "D:/123/");
// new File();
}
}
Q3: 用java实现ftp侧压缩文件的解压
我们在开发项目的时候,特别是B/S系统,经常会遇到要批量上传文件的需求,对此需求一般有如下几个解决方案(以B/S为例):1. 在客户端提供文件上传接口,一次上传一个文件2. 一次上传多个文件3. 将需要上传的文件打包,一次上传到服务器,并自动解压到指定目录1,2方法都有几个很明显的不足,用户工作量大,文件如果过大,在网络环境中,上传的效率低下,另外文件在不同的目录,是无法进行一次选择上传的.所以打包上传就成为了比较流行的批量文件上传的解决方案,下面就来一起讨论一下在java中如何实现: 主要功能需求: a. 上传文件,将文件保存在服务器 b. 读取服务器上压缩文件,解压到指定目录 下面就这两个需求说说编码实现上传: 使用了smartupload开源程序 参考链接:
java解压文件的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java解压包、java解压文件的代码的信息别忘了在本站进行查找喔。








