用java程序高效的解压jar文件,希望指教
我写了一个方法,但是占有大量的cpu,希望大侠指教
我的代码入下:
public static boolean unJarFile(String jarFileName,String outputDirectory)
{
JarInputStream in=null;
try
{
in=new JarInputStream(new FileInputStream(jarFileName));
JarEntry jen;
while((jen=in.getNextJarEntry())!=null)
{
if(jen.isDirectory())
{
String name = jen.getName();
name = name.substring(0, name.length() - 1);
File file = new File(outputDirectory + File.separator + name);
file.mkdir();
}
else
{
String fname=outputDirectory + File.separator + jen.getName().substring(0,jen.getName().indexOf("/"));
File dt=new File(fname);
if(!dt.exists())
{
dt.mkdir();
}
File file = new File(outputDirectory + File.separator + jen.getName());
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
int b;
while ( (b = in.read()) != -1){
out.write(b);
}
out.close();
}
}
in.close();
}
catch(Exception e)
{
try {
//e.printStackTrace();
in.close();
return false;
}
catch (IOException ex) {
return false;
}
}
return true;
}
希望能有一个高效的算法
问题点数:20、回复次数:4Top
1 楼zzzle(Vincent)回复于 2005-07-21 21:20:11 得分 0
看AnT源码Top
2 楼zzzle(Vincent)回复于 2005-07-21 21:21:45 得分 0
另你写了啥算法啊,不就是调用了...Top
3 楼lzh302216(123)回复于 2005-07-22 08:42:10 得分 0
希望楼上的指教,谢谢,我的qq94090973Top
4 楼zzzle(Vincent)回复于 2005-07-24 09:04:42 得分 0
你看一下Ant中解压Jar的源代码就好了,我其实也是刚开始学习的。Top



