将解压缩的文件保存到一个文件夹中
本文关键字:一个 文件夹 解压缩 文件 保存 | 更新日期: 2023-09-27 18:10:29
我想将解压缩的文件保存到IsolatedStorage中的一个文件夹中。我已经从IsolatedStorage中读取了文件压缩文件,现在想将它们解压缩到一个文件夹中。我试过这样做:-
private async Task UnZipFile(string fileName)
{
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.ReadWrite))
{
UnZipper unzip = new UnZipper(fileStream);
var filename = unzip.FileNamesInZip.FirstOrDefault();
if (filename != null)
{
// i can have the stream too. like this.
// var zipStream = unzip.GetFileStream(filename)
// here i am not getting how to save unzip file to a folder.
}
}
这是我得到的:)希望它能帮助到别人。
private async Task UnZipFile()
{
// you can use Isolated storage too
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));
}
}
}
}
}