string sFileName = Path.GetFileName(FileToZip);
if (!File.Exists(FileToZip))
{
throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
}
FileStream fs = File.OpenRead(FileToZip);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close(); FileStream ZipFile = File.Create(ZipedFile);
ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
ZipEntry ZipEntry = new ZipEntry(sFileName);
ZipEntry.DateTime = DateTime.Now; string p = "a";
ZipStream.Password = p;
ZipStream.SetComment("密码为:" + ZipStream.Password);
ZipStream.SetLevel(6); ZipStream.PutNextEntry(ZipEntry); ZipStream.Write(buffer, 0, buffer.Length);
ZipStream.Finish();
ZipStream.Close();
能用SharpZipLib加密压缩文件,用SharpZipLib的代码也能解密解压。
我把密码写在备注中,用winrar打开后显示‘密码为:a’
但,问题是,我用winrar却无法解密解压该文件,输入密码‘a'却报密码错误。
那么,用winrar解压该文件时,该用什么密码呢?
或者是你压缩的问题:)