简体   繁体   中英

ZipStorer not creating any file in Android c#

Hi i am using Xamarin with c# to make an app that can zip and unzip files so after a few tries i found zipStorer.

http://zipstorer.codeplex.com/

Here is my code

 ZipStorer zip = ZipStorer.Open(Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/aaa.zip")), FileAccess.Read);

                List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                string path;

                foreach (ZipStorer.ZipFileEntry entry in dir)

                {

                    if (Path.GetFileName(entry.FilenameInZip) == "08.jpg")

                    {

                        path = Path.Combine(Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/")), Path.GetFileName(entry.FilenameInZip));

                        zip.ExtractFile(entry, Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/sample.jpg")));

                        break;

                    }   

                }

                zip.Close();

After a couple of hours the code is running fine and opening the zip and showing all in the console but no zip is being created... am i doing something wrong?

Internally ZipStorer uses the character set 437 to do the encoding and un-encoding (line 85 in ZipStorer.cs):

    private static Encoding DefaultEncoding = Encoding.GetEncoding(437);

Xamarin does not include this character set by default when you build your application. As stated in the Localisation And Internationalisation document:

To reduce the size of the application, Xamarin.iOS doesn't include any specific encoding, and you have to instruct mtouch to include the assemblies containing the support for the encoding you need.

To include the character set, add the West character set through the internationalisation settings in your application:

在此处输入图片说明 Ensure you check this for both Debug AND Release .

I could not get this to work for me when I was adding zip support to my application. In the end I rolled my own zip support by using the Java IO libraries but there may be a component available to add cross platform zip support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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