我有一个压缩文件。该文件还包含各种目录和文件。我想提取所有这些并保存在指定的路径中。什么是使用java提取zip文件的最佳方式
那么如何编写一个java程序来提取压缩文件。
感谢 苏尼尔·库马尔Sahoo
我有一个压缩文件。该文件还包含各种目录和文件。我想提取所有这些并保存在指定的路径中。什么是使用java提取zip文件的最佳方式
那么如何编写一个java程序来提取压缩文件。
感谢 苏尼尔·库马尔Sahoo
public static void unzip(){
try{
BufferedOutputStream out = null;
ZipInputStream in = new ZipInputStream(ZipFileExtracter.class.getClassLoader().getResourceAsStream("com/artificialmachines/chitme/stamps/ChitMeData.zip"));
ZipEntry entry;
boolean isDirectory=false;
while((entry = in.getNextEntry()) != null){
int count;
byte data[] = new byte[BUFFER];
// write the files to the disk
String entryName = entry.getName();
File newFile = new File(new StringBuffer().append(System.getProperty("user.dir")).append(File.separator).append(entryName).toString());
if(entryName.endsWith("/")){
isDirectory=true;
newFile.mkdir();
//System.out.println("This is directory "+newFile.exists()+" IS DIr "+newFile.isDirectory()+" path "+newFile.getPath());
}else{
newFile.createNewFile();
}
if(!isDirectory){
out = new BufferedOutputStream(new FileOutputStream(newFile),BUFFER);
while ((count = in.read(data,0,BUFFER)) != -1){
out.write(data,0,count);
}
cleanUp(out);
}
isDirectory=false;
}
cleanUp(in);
}
catch(Exception e){
e.printStackTrace();
System.exit(0);
}
}
的
你应该考虑使用java.util.zip
package。 Sun提供了如何使用它的教程:Compressing and Decompressing Data Using Java APIs。
当然。在这种情况下,http://lmgtfy.com/?q=java+unzip可能是最好的网址 – 2009-11-10 05:44:37
java.util.zip。*执行所需的操作。 查看参考API。如果您正在寻找例如LookThis
可能重复[如何解压递归的Java文件?(http://stackoverflow.com/questions/981578/how-to-unzip-files-recursively-in -java) – Kevin 2014-05-07 02:10:50