2013-05-17 91 views
-1

我一直在使用在this website上找到的解壓縮代碼。該代碼應該是完美的工作,並能夠解壓縮文件夾/子文件夾。Android - 無法解壓縮文件

問題是,當我運行的代碼,它給我上的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 

做任何人都知道這是什麼情況? 請幫忙。

+2

那麼它看起來像文件不存在...... –

+2

大概解壓/文件不會退出 – Blackbelt

+0

沒錯!這就是解壓縮不起作用的原因。但我只是不知道它爲什麼對一些人(自動創建子文件夾)的原因,但不與我... – falcon

回答

1

此錯誤的主要原因是因爲文件夾/子文件夾(解壓縮/文件)不存在。所以,在我加入這幾行的問題解決了:

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

但是,我並沒有聲稱原始代碼是錯誤的,因爲它實際上對大多數人都有效。另外,我不知道爲什麼原始代碼不適合我。 – falcon