简体   繁体   English

将 zip 文件解压到目录

[英]Extract zip file to directory

I am extracting zip file to directory using emulator and Xamarin studio C# Bt i am getting numbers of errors I have tried number of ways but could not solve this.How can I solve this.Here is my code:我正在使用模拟器和 Xamarin 工作室 C# 将 zip 文件提取到目录中

   string zipPath=("/storage/emulated/0/Download/file/file/file.epub");
    string extractPath = ("/storage/emulated/0/Download/file/file/temp");
    DateTime time = new DateTime(2016, 12, 30);
    if (File.Exists(extractPath))
        File.SetLastWriteTime(extractPath, time);
    ZipFile.ExtractToDirectory(zipPath, extractPath);

but i am getting errors like:但我收到如下错误:

[MonoDroid] System.IO.IOException: Invalid parameter
[MonoDroid]   at System.IO.File.SetLastWriteTime (System.String path, System.DateTime lastWriteTime) [0x00030] in <500f590720b848ecadaddac3c375ddb5>:0 
[MonoDroid]   at AD_Forms.AD..ctor () [0x00061] in <21d9786453cc4650b478317d331d91ab>:0 
[MonoDroid]   at AD_Forms.App..ctor () [0x00006] in <21d9786453cc4650b478317d331d91ab>:0 
[MonoDroid]   at AD_Forms.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00022] in <21d9786453cc4650b478317d331d91ab>:0 
[MonoDroid]   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <27c17fe440cf491ba8255bcefade6e02>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object:a118a7e9-2106-4f87-a55c-98f583aa9bd8 (intptr,intptr,intptr)
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.companyname.ad_forms, PID: 1909
[AndroidRuntime] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[AndroidRuntime]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
[AndroidRuntime] Caused by: java.lang.reflect.InvocationTargetException
[AndroidRuntime]    at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
[AndroidRuntime]    ... 1 more
[AndroidRuntime] Caused by: android.runtime.JavaProxyThrowable: System.IO.IOException: Invalid parameter
[AndroidRuntime]   at System.IO.File.SetLastWriteTime (System.String path, System.DateTime lastWriteTime) [0x00030] in <500f590720b848ecadaddac3c375ddb5>:0 
[AndroidRuntime]   at AD_Forms.AD..ctor () [0x00061] in <21d9786453cc4650b478317d331d91ab>:0 
[AndroidRuntime]   at AD_Forms.App..ctor () [0x00006] in <21d9786453cc4650b478317d331d91ab>:0 
[AndroidRuntime]   at AD_Forms.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00022] in <21d9786453cc4650b478317d331d91ab>:0 
[AndroidRuntime]   at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <27c17fe440cf491ba8255bcefade6e02>:0 
[AndroidRuntime]   at (wrapper dynamic-method) System.Object:a118a7e9-2106-4f87-a55c-98f583aa9bd8 (intptr,intptr,intptr)
[AndroidRuntime]    at md595826e4c93c1bb9112307fcbc37b1beb.MainActivity.n_onCreate(Native Method)
[AndroidRuntime]    at md595826e4c93c1bb9112307fcbc37b1beb.MainActivity.onCreate(MainActivity.java:29)
[AndroidRuntime]    at android.app.Activity.performCreate(Activity.java:6237)
[AndroidRuntime]    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
[AndroidRuntime]    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
[AndroidRuntime]    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
[AndroidRuntime]    at android.app.ActivityThread.-wrap11(ActivityThread.java)
[AndroidRuntime]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
[AndroidRuntime]    at android.os.Handler.dispatchMessage(Handler.java:102)
[AndroidRuntime]    at android.os.Looper.loop(Looper.java:148)
[AndroidRuntime]    at android.app.ActivityThread.main(ActivityThread.java:5417)

Do you add the permissions in the manifest file? 您是否在清单文件中添加权限?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

This bugzilla report mention that it might be due to Android's bug: https://bugzilla.xamarin.com/show_bug.cgi?id=3029 这个bugzilla报告提到它可能是由于Android的错误: https//bugzilla.xamarin.com/show_bug.cgi?id = 3029

Try to run the code in actual device instead of emulator to check whether it is also having the same problem. 尝试在实际设备中运行代码而不是模拟器来检查它是否也有同样的问题。

some android devices do not support the execution of SetLastWriteTime部分 android 设备不支持执行 SetLastWriteTime

this was even removed from ZipFile.ExtractToDirectory on a recent .NET update https://github.com/dotnet/runtime/pull/56370这甚至在最近的 .NET 更新https://github.com/dotnet/runtime/pull/56370中从 ZipFile.ExtractToDirectory 中删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM