簡體   English   中英

SevenZipSharp,如何讀取txt文件?

[英]SevenZipSharp, how to read txt file?

我正在嘗試從.7z存檔中讀取txt文件

using (StreamReader reader = new StreamReader(f + "//" + file.FileName))

但是我得到這個錯誤:

mscorlib.dll中發生了類型為'System.IO.DirectoryNotFoundException'的未處理異常。其他信息:找不到路徑'E:\\ 1.7z \\ 1 \\ 2 \\ 3 \\ New Text Document.txt'的一部分。

if (IntPtr.Size == 8) //x64
            {
                SevenZip.SevenZipExtractor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
            }
            else //x86
            {
                SevenZip.SevenZipCompressor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
            }

            string f = "E://1.7z";
            SevenZipExtractor extractor = new SevenZipExtractor(f);

            foreach (ArchiveFileInfo file in extractor.ArchiveFileData)
            {
                // Console.WriteLine("{0} : {1} Bytes", file.FileName, file.Size);

                if (file.FileName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                {
                    using (StreamReader reader = new StreamReader(f + "//" + file.FileName))
                    {
                        while (reader.Peek() >= 0)
                        {
                            Console.WriteLine("{0} ", reader.ReadLine());
                        }
                    }
                }
            }

要使用SevenZipExtractor提取文件,請使用以下命令:

String file = @"\\yourdirectory\\yourzipfile.zip";  
String directoryToExtract = @"\\yourdirectorytoextract"
using (SevenZip.SevenZipExtractor extr = new SevenZip.SevenZipExtractor(file))
{
             Console.WriteLine("Extracting File...");
             extr.ExtractArchive(directoryToExtract);
             System.IO.File.Delete(file);   
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM