c# 解压缩问题

随波流的浪 2010-01-03 11:19:56
Unexpected EOF
public class UnZipClass
{
public static void UnZip(string FileToUpZip, string ZipedFolder, string Password)
{
if (!File.Exists(FileToUpZip))
return;

if (!Directory.Exists(ZipedFolder))
Directory.CreateDirectory(ZipedFolder);


using (ZipInputStream s = new ZipInputStream(File.OpenRead(FileToUpZip)))
{

if (!string.IsNullOrEmpty(Password.Trim()))
s.Password = Password.Trim();

ZipEntry theEntry;

int size = 2048;
long fszie;
int byteLenght;
String directoryPath = null ;
String filePath = null;


while ((theEntry = s.GetNextEntry()) != null)
{

//System.Windows.Forms.MessageBox.Show(s.Length.ToString());
//Console.WriteLine(theEntry.Name);
directoryPath = ZipedFolder;

string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
directoryPath += "\\" + directoryName;
// create directory
if (directoryName.Length > 0)
{

Directory.CreateDirectory(directoryPath);
}

if (fileName != String.Empty)
{
fszie = theEntry.Size;
filePath = directoryPath + "\\" + fileName;
using (FileStream streamWriter = File.Create(filePath))
{
while (fszie > 0)
{
if (fszie > (long)size)
byteLenght = size;
else
byteLenght = Convert.ToInt32(fszie);
fszie = fszie - size;
byte[] data = new byte[byteLenght];
s.Read(data, 0, byteLenght);
streamWriter.Write(data, 0, byteLenght);
}
}
}
}
}


}


public static void UnZip(string FileToUpZip, string ZipedFolder)
{
UnZip(FileToUpZip, ZipedFolder, "");
}

#endregion

}

在 while ((theEntry = s.GetNextEntry()) != null)的地方 s.GetNextEntry()) 会抛出 Unexpected EOF 请问这个问题如何解决

...全文
227 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xigahe 2012-01-04
  • 打赏
  • 举报
回复
怎么解决的?
TKDPC 2010-05-23
  • 打赏
  • 举报
回复
这么快
搞定了
随波流的浪 2010-05-23
  • 打赏
  • 举报
回复 1
这个问题我已经解决了
林三一 2010-01-03
  • 打赏
  • 举报
回复
ding

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧