tôi đã sau mã từ net và có vẻ mọi thứ đều đúng nhưng tôi nhận được không tìm thấy tập tin ngoại lệ ...giải nén một file zip ... File not found ngoại lệ
Tôi có một tập tin gọi là NewForestPonies. epub trong sdcard
Permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Mã sản phẩm:
String ZipFileLocation=Environment.getExternalStorageDirectory()+"/NewForestPonies.epub";
String unZipFileLocation=Environment.getExternalStorageDirectory()+"/DEST/";
Decompress decomp=new Decompress(ZipFileLocation, unZipFileLocation, "zip");
decomp.run();
public Decompress(String zipFile, String location,String t) {
super(t);
_zipFile = zipFile;
_location = location;
}
public void run() {
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();
}
//MyDownloadListener.progress=70;
zin.close();
}catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
finally {
try {
fin.close();
zin.close();
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
errror:
03-20 15:49:15.909: ERROR/Decompress(9479): java.io.FileNotFoundException: /mnt/sdcard/DEST/NewForestPonies/iTunesMetadata.plist (Not a directory)
03-20 15:49:15.909: ERROR/Decompress(9479): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-20 15:49:15.909: ERROR/Decompress(9479): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:239)
03-20 15:49:15.909: ERROR/Decompress(9479): at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
03-20 15:49:15.909: ERROR/Decompress(9479): at java.io.FileOutputStream.<init>(FileOutputStream.java:77)
03-20 15:49:15.909: ERROR/Decompress(9479): at com.AndroidExplorer.Decompress.run(Decompress.java:42)
03-20 15:49:15.909: ERROR/Decompress(9479): at com.AndroidExplorer.DecompressActivity.onCreate(DecompressActivity.java:23)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.os.Looper.loop(Looper.java:132)
03-20 15:49:15.909: ERROR/Decompress(9479): at android.app.ActivityThread.main(ActivityThread.java:4028)
03-20 15:49:15.909: ERROR/Decompress(9479): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 15:49:15.909: ERROR/Decompress(9479): at java.lang.reflect.Method.invoke(Method.java:491)
03-20 15:49:15.909: ERROR/Decompress(9479): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
03-20 15:49:15.909: ERROR/Decompress(9479): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
03-20 15:49:15.909: ERROR/Decompress(9479): at dalvik.system.NativeStart.main(Native Method)
kiểm tra xem bạn có file trong đường dẫn này /mnt/sdcard/EPUB/META-INF/container.xml –
@Samir i chỉ có zip filee .. tôi có cần tạo thư mục đích và tập tin theo cách thủ công không? của nó được thực hiện trong mã phải không? – vnshetty
Bạn có quyền viết trên thẻ sd không? – Jerome