阅读:2483回复:1
[分享]利用java来解压
<P>import org.apache.tools.ant.taskdefs.*;<BR>import org.apache.tools.ant.*;<BR>import java.io.*;<BR>import java.util.*;</P>
<P>public class FreeFunc{<BR> public boolean unzip(String zipFilepath, String destinationDir) { <BR> final class Expander extends Expand { <BR> public Expander() { <BR> project = new Project(); <BR> project.init(); <BR> taskType = "unzip"; <BR> taskName = "unzip"; <BR> target = new Target(); <BR> } <BR> } <BR> boolean success=false;<BR> try{<BR> <BR> Expander expander = new Expander(); <BR> expander.setEncoding("GBK"); <BR> expander.setSrc(new File(zipFilepath));<BR> File file= new File(zipFilepath);<BR> String folder = file.getName();<BR> folder=folder.substring(0,(folder.length()-4));<BR> //System.out.println(folder);<BR> expander.setDest(new File(destinationDir + "\\" + folder)); <BR> expander.execute(); <BR> success=true;<BR> } catch(Exception e){<BR> success=false;<BR> System.out.println(e.toString());<BR> }<BR> return success;<BR> }</P> <P> public static void main(String[] args)throws Exception{<BR> //unzip("E:\\Download\\2.zip","E:\\Download");<BR> FreeFunc free = new FreeFunc();<BR> free.unzip("E:\\Download\\21.zip","E:\\Download");<BR> }<BR><BR>}<BR></P> |
|
1楼#
发布于:2007-04-05 21:19
<img src="images/post/smile/dvbbs/em03.gif" />
|
|