如何在Windows Phone 8应用中的IsolatedStorage中解压缩文件? [英] How to unzip a file in IsolatedStorage in windows phone 8 app?

查看:114
本文介绍了如何在Windows Phone 8应用中的IsolatedStorage中解压缩文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序内部,我试图一次下载约180个小音频文件。我尝试了BackgroundTransferService,但对于许多小文件来说似乎并不稳定。因此,现在我要下载所有这些音频的ZIP文件,并希望将其提取到音频文件夹中。我在此线程中尝试了该方法:

Inside my app, I am trying to download about 180 small audio files all at once. I tried the BackgroundTransferService, but it does not seem stable with so many small files. So, now I am downloading a ZIP of all those audio and want extract them in "audio" folder. I tried the method in this thread:

如何在Windows Phone中解压缩文件8

但是我收到此错误:mscorlib.ni.dll中发生了'System.IO.IOException'... 在以下代码中。我该如何克服这个问题?

But I get this error: 'System.IO.IOException' occurred in mscorlib.ni.dll... in the following code. How can I overcome this issue?

while (reader.ReadInt32() != 101010256)
{
   reader.BaseStream.Seek(-5, SeekOrigin.Current);  // this line causes error
}...

此外,我需要在哪里

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(@"audio.rar", FileMode.Open, FileAccess.ReadWrite))
{
    UnZipper unzip = new UnZipper(fileStream);                               
    foreach (string filename in unzip.FileNamesInZip())
    {
       string FileName = filename;
    }
}


推荐答案

I刚刚解决了这个问题。您可以做的就是使用此方法,您的文件将被保存到zip文件中存在的适当文件夹结构的独立存储中。您可以根据需要在数据存储位置进行更改。

I have just solved this. what you can do is use this method and your file will go save to isolated storage in proper folder structure as present in your zip file. you can change according to your need where you want to store the data.

我刚刚阅读了sample.zip文件。

I have just read a sample.zip file. From your app folder.

private async Task UnZipFile()
    {
        var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
        using (var fileStream = Application.GetResourceStream(new Uri("sample.zip", UriKind.Relative)).Stream)
        {
            var unzip = new UnZipper(fileStream);
            foreach (string filename in unzip.FileNamesInZip)
            {
                if (!string.IsNullOrEmpty(filename))
                {
                    if (filename.Any(m => m.Equals('/')))
                    {
                        myIsolatedStorage.CreateDirectory(filename.Substring(0, filename.LastIndexOfAny(new char[] { '/' })));
                    }

                    //save file entry to storage
                    using (var streamWriter =
                        new StreamWriter(new IsolatedStorageFileStream(filename,
                            FileMode.Create,
                            FileAccess.ReadWrite,
                            myIsolatedStorage)))
                    {
                        streamWriter.Write(unzip.GetFileStream(filename));
                    }
                }
            }
        }
    }

欢呼:)

这篇关于如何在Windows Phone 8应用中的IsolatedStorage中解压缩文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆