zoukankan      html  css  js  c++  java
  • metro压缩和解压文件

    在1.zip中增加一张新图片
    StorageFile jpg = await KnownFolders.PicturesLibrary.GetFileAsync("1.jpg"); StorageFile zip = await KnownFolders.PicturesLibrary.GetFileAsync("1.zip");
    //把上面这句改成如下就成了压缩文件
    //StorageFile zip = await KnownFolders.PicturesLibrary.CreateFileAsync(jpg.DisplayName+".zip",CreationCollisionOption.ReplaceExisting);
      
      
    using (ZipArchive archive = new ZipArchive((await zip.OpenAsync(FileAccessMode.ReadWrite)).AsStream(), ZipArchiveMode.Update)) { ZipArchiveEntry readmeEntry = archive.CreateEntry(jpg.Name); byte[] buffer = WindowsRuntimeBufferExtensions.ToArray(await FileIO.ReadBufferAsync(jpg)); using (var writer = readmeEntry.Open()) { await writer.WriteAsync(buffer, 0, buffer.Length); } }
     
    把1.jpg从1.zip中删除
    StorageFile zip = await KnownFolders.PicturesLibrary.GetFileAsync("1.zip"); using (ZipArchive archive = new ZipArchive((await zip.OpenAsync(FileAccessMode.ReadWrite)).AsStream(), ZipArchiveMode.Update)) { //删除文件 archive.GetEntry("1.jpg").Delete(); }
     
    //导出1.jpg,newFile为要到出的文件
    
    StorageFile zip = await KnownFolders.PicturesLibrary.GetFileAsync("1.zip");
                using (ZipArchive archive = new ZipArchive((await zip.OpenAsync(FileAccessMode.ReadWrite)).AsStream(), ZipArchiveMode.Update))
                {
                ZipArchiveEntry zipArchiveEntry = archive.GetEntry("1.jpg").
                using (Stream fileData = zipArchiveEntry.Open())
                                {
                                    StorageFile newFile = await KnownFolders.PicturesLibrary.CreateFileAsync(zipArchiveEntry.FullName, CreationCollisionOption.ReplaceExisting);
                                    using (IRandomAccessStream newFileStream = await newFile.OpenAsync(FileAccessMode.ReadWrite))
                                    {
                                        using (Stream s = newFileStream.AsStreamForWrite())
                                        {
                                            await fileData.CopyToAsync(s);
                                            await s.FlushAsync();
                                        }
                                    }
                                }
    
    
          }


    参考资料:http://www.cnblogs.com/vistach/archive/2012/11/05/Windows8_Win8_WinRT_MetroStyleApps_ModernUIApps_Zip_UnZip_Compress_Decompression.html

  • 相关阅读:
    python 购物车和三级菜单
    python-装饰器
    day3 python 函数
    day3 python 集合 文件
    two day python基础知识
    python-day 1
    Cordova 环境搭建
    javascript在html直接传值
    JavaScript疑难点
    Javascript创建对象的方法
  • 原文地址:https://www.cnblogs.com/wangjinming/p/3582869.html
Copyright © 2011-2022 走看看