[英]SevenZipSharp, how to read txt file?
I am trying to read txt files from .7z archive 我正在尝试从.7z存档中读取txt文件
using (StreamReader reader = new StreamReader(f + "//" + file.FileName))
but I get this error: 但是我得到这个错误:
An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll Additional information: Could not find a part of the path 'E:\\1.7z\\1\\2\\3\\New Text Document.txt'. 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());
}
}
}
}
To use SevenZipExtractor to extract a file, use the following: 要使用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.