1

我正在尝试访问 .7z 文件中的文件。我知道 zip 文件夹中文件的名称,并且它存在于 .7z 文件中。以前我使用的是 ExtractArchive(templocation),它只是将所有文件转储到一个临时位置。现在我希望能够在不提取整个 .7z 文件的情况下获取特定文件。

7Zip 有一个名为 SevenZipExtractor 的类,它有一个方法 ExtractFile。我认为这就是我正在寻找的东西,但我找不到任何像样的文档。

我需要澄清的是如何正确传递 Stream 参数。我正在使用这样的代码;

//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);
}
4

1 回答 1

0

设置FileStreamSevenZip 可以写出的:

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);
    }
}
于 2013-06-20T19:57:48.947 回答