Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下载zip文件并解压缩到内部存储Android Xamarin跨平台应用程序_Xamarin_Xamarin.forms - Fatal编程技术网

下载zip文件并解压缩到内部存储Android Xamarin跨平台应用程序

下载zip文件并解压缩到内部存储Android Xamarin跨平台应用程序,xamarin,xamarin.forms,Xamarin,Xamarin.forms,是否有任何方法可以使用Xamarin跨平台应用程序从远程服务器下载和解压缩文件。 我使用PC:Storage librray与文件和文件夹进行交互 IFolder rootFolder = FileSystem.Current.LocalStorage; IFolder folder = await rootFolder.CreateFolderAsync("MyAppRoot\\F1",CreationCollisionOption.OpenIfExists);

是否有任何方法可以使用Xamarin跨平台应用程序从远程服务器下载和解压缩文件。 我使用PC:Storage librray与文件和文件夹进行交互

IFolder rootFolder = FileSystem.Current.LocalStorage;
        IFolder folder = await rootFolder.CreateFolderAsync("MyAppRoot\\F1",CreationCollisionOption.OpenIfExists);
        IFile file = await folder.CreateFileAsync("firstfile.txt",
            CreationCollisionOption.ReplaceExisting);
        await file.WriteAllTextAsync("my content");
这就是我在app root文件夹中创建文件夹F1的方式,创建了files firstfile.txt并向其中写入了一些内容。但是我怎样才能对zip文件执行相同的操作呢? 下载zip文件,将内容解压缩到文件夹


另外,如何查看在运行应用程序时创建的文件夹/文件?Xamarin android emulator是否有可用的IsoStoreSpy工具?

第一步,获取文件:

沙马林有帮助

以下是他们的下载任务,以防链接移动/消失:

public static async Task<int> CreateDownloadTask(string urlToDownload, IProgress<DownloadBytesProgress> progessReporter)
{
int receivedBytes = 0;
int totalBytes = 0;
WebClient client = new WebClient();

using (var stream = await client.OpenReadTaskAsync(urlToDownload))
{
    byte[] buffer = new byte[4096];
    totalBytes = Int32.Parse(client.ResponseHeaders[HttpResponseHeader.ContentLength]);

    for (;;)
    {
        int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
        if (bytesRead == 0)
        {
            await Task.Yield();
            break;
        }

        receivedBytes += bytesRead;
        if (progessReporter != null)
        {
            DownloadBytesProgress args = new DownloadBytesProgress(urlToDownload, receivedBytes, totalBytes);
            progessReporter.Report(args);
        }
    }
}
return receivedBytes;
}
然后是解压,我知道我以前下载过。。。浏览一下我在System.IO.Compression命名空间中使用DeflateStream解压的一些代码


由于您已经有了处理本地文件的功能,我不会再提任何内容。

您找到了吗?我有一个问题的答案,如果您想查看emulator的数据,您可以使用Android设备监视器(DDMS)查看,您将在visual studio 2015中Android设备日志图标的最左侧找到它,请记住,它只有在应用程序运行时才起作用。
await zipFile.WriteAsync(buffer, 0, bytesRead);