我正在尝试解压缩一个 zip 文件。该文件包含其他几个文件。我使用的方法是:
private void unzipFile(String inputFileName,String outputDirName){
int dataCount=0;
byte[] dataArr=null;
File inputZipFile=null,targetDir=null,unzipFile=null;
ZipInputStream zipIPStream=null;
ZipEntry zipEntry=null;
BufferedOutputStream bfrOPStream=null;
FileOutputStream unzipOPStream=null;
try{
inputZipFile=new File(inputFileName);
targetDir=new File(outputDirName);
zipIPStream=new ZipInputStream(new BufferedInputStream(new FileInputStream(inputZipFile)));
while((zipEntry=zipIPStream.getNextEntry())!=null){
dataArr=new byte[2048];
// zipEntry=zipIPStream.getNextEntry();
System.out.println("ZipEntry:"+zipEntry.getName());
unzipFile=new File(targetDir.getAbsolutePath()+"/"+zipEntry.getName());
System.out.println("Checking the path:"+unzipFile.getPath());
if(!unzipFile.getParentFile().exists()){
unzipFile.getParentFile().mkdirs();
}
unzipOPStream=new FileOutputStream(targetDir.getPath()+"/"+zipEntry.getName());
bfrOPStream=new BufferedOutputStream(unzipOPStream,2048);
while((dataCount=zipIPStream.read(dataArr,0,2048))!=-1){
unzipOPStream.write(dataArr,0,dataCount);
}
unzipOPStream.flush();
unzipOPStream.close();
}
}catch(IOException ioe){
ioe.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
if(zipIPStream!=null){
try{
zipIPStream.close();
}catch(Exception e){
}
}
}
}
该方法抛出以下错误
10-22 13:33:09.896: W/System.err(446): java.io.FileNotFoundException: /mnt/sdcard/iR/testbook/Caterpillar-Insect-Animal-Macro-HD-600x375.jpg (Not a directory)