0

ファイルを解凍するクラスがあります。zip にフォルダーが含まれていない場合は正常に動作します。そうであれば、エラーをスローするだけです。

彼女の私のクラス:

public class Decompress
{
private String _zipFile;
private String _location;
ZipEntry ze = null;

public Decompress(String zipFile, String location)
{
    _zipFile = zipFile;
    _location = location;

    _dirChecker("");
}

public void unzip()
{
    try
    {
        FileInputStream fin = new FileInputStream(_zipFile);
        ZipInputStream zin = new ZipInputStream(fin);
        while ((ze = zin.getNextEntry()) != null)
        {
            Log.v("Decompress", "Unzipping " + ze.getName()); 

            if (ze.isDirectory())
            {
                _dirChecker(ze.getName());
            }
            else
            {
                FileOutputStream fout = new FileOutputStream(_location + ze.getName());
                for (int c = zin.read(); c != -1; c = zin.read())
                {
                    fout.write(c);
                }

                zin.closeEntry();
                fout.close();
            } 

        }
        zin.close();
    }
    catch (Exception e)
    {
        Log.e("Decompress", "unzip", e);
    }

}

private void _dirChecker(String dir)
{
    File f = new File(_location + dir);

    Log.d("Decompress", f.getAbsolutePath().toString());

    if (!f.isDirectory())
    }
        f.mkdirs();
    }
}

これが私のlogcatです:

01-07 07:33:49.941 D/Decompress(19375): /sdcard/test
01-07 07:33:49.941 V/Decompress(19375): Unzipping META-INF/
01-07 07:33:49.941 D/Decompress(19375): /sdcard/test/META-INF
01-07 07:33:49.941 V/Decompress(19375): Unzipping META-INF/CERT.RSA
01-07 07:33:49.949 E/Decompress(19375): unzip
01-07 07:33:49.949 E/Decompress(19375): java.io.FileNotFoundException: /sdcard/test/META-INF/CERT.RSA: open failed: ENOENT (No such file or directory)
01-07 07:33:49.949 E/Decompress(19375):     at libcore.io.IoBridge.open(IoBridge.java:416)
01-07 07:33:49.949 E/Decompress(19375):     at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
01-07 07:33:49.949 E/Decompress(19375):     at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
01-07 07:33:49.949 E/Decompress(19375):     at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
01-07 07:33:49.949 E/Decompress(19375):     at com.mycompany.myapp3.Decompress.unzip(Decompress.java)
01-07 07:33:49.949 E/Decompress(19375):     at com.mycompany.myapp3.MainActivity.onCreate(MainActivity.java)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.Activity.performCreate(Activity.java:5108)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2263)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.ActivityThread.access$600(ActivityThread.java:153)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
01-07 07:33:49.949 E/Decompress(19375):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 07:33:49.949 E/Decompress(19375):     at android.os.Looper.loop(Looper.java:137)
01-07 07:33:49.949 E/Decompress(19375):     at android.app.ActivityThread.main(ActivityThread.java:5202)
01-07 07:33:49.949 E/Decompress(19375):     at java.lang.reflect.Method.invokeNative(Native Method)
01-07 07:33:49.949 E/Decompress(19375):     at java.lang.reflect.Method.invoke(Method.java:511)
01-07 07:33:49.949 E/Decompress(19375):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
01-07 07:33:49.949 E/Decompress(19375):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
01-07 07:33:49.949 E/Decompress(19375):     at dalvik.system.NativeStart.main(Native Method)
01-07 07:33:49.949 E/Decompress(19375): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
01-07 07:33:49.949 E/Decompress(19375):     at libcore.io.Posix.open(Native Method)
01-07 07:33:49.949 E/Decompress(19375):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
01-07 07:33:49.949 E/Decompress(19375):     at libcore.io.IoBridge.open(IoBridge.java:400)
01-07 07:33:49.949 E/Decompress(19375):     ... 19 more
4

1 に答える 1

0

さて、私はこれを修正してコードを書き直します。同じコードなので何が起こったのかよくわかりません。しかし、今ではうまく機能しています。

于 2013-01-31T18:57:36.687 に答える