Android - 无法解压缩文件

时间:2013-05-17 13:39:19

标签: java android file zip

我一直在使用this website上的解压缩代码。代码应该完全正常,并且能够解压缩文件夹/子文件夹。

问题是当我运行代码时,它在logcat上给我错误:

05-17 20:31:13.415: V/Decompress(27611): Unzipping files/pkey.txt
05-17 20:31:13.430: E/Decompress(27611): unzip
05-17 20:31:13.430: E/Decompress(27611): java.io.FileNotFoundException: /storage/sdcard0/unzipped/files/pkey.txt: open failed: ENOENT (No such file or directory)
05-17 20:31:13.430: E/Decompress(27611):    at libcore.io.IoBridge.open(IoBridge.java:416)
05-17 20:31:13.430: E/Decompress(27611):    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
05-17 20:31:13.430: E/Decompress(27611):    at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
05-17 20:31:13.430: E/Decompress(27611):    at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
05-17 20:31:13.430: E/Decompress(27611):    at id.ac.petra.ta.DriveActivity$Decompress.unzip(DriveActivity.java:316)
05-17 20:31:13.430: E/Decompress(27611):    at id.ac.petra.ta.DriveActivity$DownloadFile.doInBackground(DriveActivity.java:371)
05-17 20:31:13.430: E/Decompress(27611):    at id.ac.petra.ta.DriveActivity$DownloadFile.doInBackground(DriveActivity.java:1)
05-17 20:31:13.430: E/Decompress(27611):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-17 20:31:13.430: E/Decompress(27611):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-17 20:31:13.430: E/Decompress(27611):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-17 20:31:13.430: E/Decompress(27611):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-17 20:31:13.430: E/Decompress(27611):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-17 20:31:13.430: E/Decompress(27611):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-17 20:31:13.430: E/Decompress(27611):    at java.lang.Thread.run(Thread.java:856)
05-17 20:31:13.430: E/Decompress(27611): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
05-17 20:31:13.430: E/Decompress(27611):    at libcore.io.Posix.open(Native Method)
05-17 20:31:13.430: E/Decompress(27611):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
05-17 20:31:13.430: E/Decompress(27611):    at libcore.io.IoBridge.open(IoBridge.java:400)
05-17 20:31:13.430: E/Decompress(27611):    ... 13 more

有谁知道这是怎么回事? 请帮忙。

1 个答案:

答案 0 :(得分:1)

此错误的主要原因是文件夹/子文件夹(解压缩/文件)不存在。所以,在我添加这几行之后问题就解决了:

java.io.File f = new java.io.File(_location + ze.getName());
f = new java.io.File(f.getParent());
f.mkdirs();