【发布时间】:2011-03-07 06:24:51
【问题描述】:
如何在java中删除一个zip文件? file.delete 方法返回 false。为什么?
File file = new File("/mibook/"+mFilename+"/"+mZipname.toString());
boolean deleted = file.delete();
编辑:
规则“目录在删除前应该为空..”是否适用于 zip 文件?
我的文件解压码
public void unzip() throws IOException {
FileInputStream fin=null;
ZipInputStream zin=null;
File file =null;
ZipEntry ze ;
FileOutputStream fout=null;
try{
System.out.println(_zipFile );
System.out.println(_location);
fin = new FileInputStream(_zipFile);
zin = new ZipInputStream(fin);
ze= null;
byte[] buffer = new byte[1024];
int length;
while ((ze = zin.getNextEntry()) != null) {
file = new File((_location +"/" + ze.getName()));
file.getParentFile().mkdirs();
fout= new FileOutputStream(_location + ze.getName());
while ((length = zin.read(buffer))>0) {
fout.write(buffer, 0, length);
}
zin.closeEntry();
fout.close();
}
zin.close();
}catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
finally {
fin.close();
zin.close();
fout.close();
}
}
【问题讨论】:
-
请贴出你用过的代码。
-
为了尽快获得更好的帮助,请发布 SSCCE (pscode.org/sscce.html)。鉴于问题代码下载的是 Zip,您可以使用我网站 (pscode.org/jws/api.html#bs) 上的 basicservice.zip 文件,它很小,约为 3Kb。
标签: java delete-file