导读:
InAndOut(zf,fi);
}
zf.close();
long end=System.currentTimeMillis();
System.out.println('/n'+" "+'/n'+"耗用时间(秒): "+(end-start)/1000+" "+'/n'+" -----恭喜您! 解压成功!!!");
}
public static void InAndOut(ZipFile zf,ZipEntry ze) throws Exception
{
if(ze.isDirectory())
{
File f=new File(copyDir+ze.getName());
f.mkdirs();
}
else
{
InputStream in=zf.getInputStream(ze);
FileOutputStream out=new FileOutputStream(copyDir+ze.getName());
byte[] buf= new byte[2048];
int len=0;
while((len=in.read(buf))>0)
{
out.write(buf,0,len);
}
out.close();
in.close();
}
}
}
此程序接受两个参数 第一个是你要解压的ZIP文件 第二个是你所要解压到的目录 例如是c:/ wang目录 要输入c:/ wang / 才能达到预想的 效果!! 由于java.util.zip包对中文目录问题的不支持 所以本程序不能压缩中文目录和文件,如果想解决这个问题的话可以去apache去下载一个名为org.apache.tools.zip 包 可以解决这个中文目录名问题....
==========================
==========================
<script type=text/javascript>
</script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript>
</script>
Tags:[java] [文件]
package cn.itcast;
import java.io.*;
import java.util.zip.*;
import java.util.*;
public class OpenZipFile
{
static String copyDir=null;
public static void main(String args[]) throws Exception
{
long start=System.currentTimeMillis();
copyDir=args[1];
ZipFile zf=new ZipFile(args[0]);
Enumeration en=zf.entries();
while(en.hasMoreElements())
{
ZipEntry fi=(ZipEntry)en.nextElement();
System.out.println(fi.getName());
InAndOut(zf,fi);
}
zf.close();
long end=System.currentTimeMillis();
System.out.println('/n'+" "+'/n'+"耗用时间(秒): "+(end-start)/1000+" "+'/n'+" -----恭喜您! 解压成功!!!");
}
public static void InAndOut(ZipFile zf,ZipEntry ze) throws Exception
{
if(ze.isDirectory())
{
File f=new File(copyDir+ze.getName());
f.mkdirs();
}
else
{
InputStream in=zf.getInputStream(ze);
FileOutputStream out=new FileOutputStream(copyDir+ze.getName());
byte[] buf= new byte[2048];
int len=0;
while((len=in.read(buf))>0)
{
out.write(buf,0,len);
}
out.close();
in.close();
}
}
}
此程序接受两个参数 第一个是你要解压的ZIP文件 第二个是你所要解压到的目录 例如是c:/ wang目录 要输入c:/ wang / 才能达到预想的 效果!! 由于java.util.zip包对中文目录问题的不支持 所以本程序不能压缩中文目录和文件,如果想解决这个问题的话可以去apache去下载一个名为org.apache.tools.zip 包 可以解决这个中文目录名问题....
Tags: [java] [文件]
本文链接地址:http://www.busfly.cn/优快云/post/478.html