zip extractFile(String file, Stream Stream)方法流参数.c#
本文关键字:Stream 方法 参数 extractFile String file zip | 更新日期: 2023-09-27 18:19:12
我正在尝试访问。7z文件中的文件。我知道zip文件夹中的文件名,也知道它存在于。7z文件中。以前我使用了ExtractArchive(模板),它只是将所有文件转储到一个临时位置。现在我希望能够抓取一个特定的文件,而不需要提取整个。7z文件。
7Zip有一个叫做SevenZipExtractor的类,它有一个ExtractFile方法。我想这就是我要找的,但我找不到任何像样的文件。
我需要澄清的是如何正确地获得传入的流参数。我正在使用这样的代码;
//this grabs the zip file and creates a FileInfo array that hold the .7z file (assume there is only one)
DirectoryInfo directoryInfo = new DirectoryInfo(ApplicationPath);
FileInfo[] zipFile = directoryInfo.GetFiles("*.7z");
//This creates the zipextractor on the zip file I just placed in the zipFile FileInfo array
using (SevenZip.SevenZipExtractor zipExtractor = new SevenZip.SevenZipExtractor(zipFile[0].FullName))
//Here I should be able to use the ExtractFile method, however I don't understand the stream parameter, and I can't find any good documentation on the method itself. What is this method looking for?
{
zipExtractor.ExtractFile("ConfigurationStore.xml", Stream stream);
}
设置一个FileStream
,使SevenZip可以写入:
DirectoryInfo directoryInfo = new DirectoryInfo(ApplicationPath);
FileInfo[] zipFile = directoryInfo.GetFiles("*.7z");
using (SevenZip.SevenZipExtractor zipExtractor = new SevenZip.SevenZipExtractor(zipFile[0].FullName))
{
using (FileStream fs = new FileStream("", FileMode.Create)) //replace empty string with desired destination
{
zipExtractor.ExtractFile("ConfigurationStore.xml", fs);
}
}