QiFeng.ZWY.Utility/ZipHelper/ZipHelper.cs
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;
namespace QiFeng.LMSD.Utility
{
public static class ZipHelper
{
/// <summary>
/// 创建压缩方法
/// </summary>
/// <param name="file">文件目录</param>
/// <param name="zipFile">保存目录</param>
public static bool CreateZipFile(string file, string zipFile)
{
var blnResult = true;
if (!File.Exists(file))
{
blnResult = false;
throw new FileNotFoundException(string.Format("文件{0}不存在!", file));
}
try
{
using (var s = new ZipOutputStream(File.Create(zipFile)))
{
s.SetLevel(9); // 压缩级别 0-9
//s.Password = "123"; //Zip压缩文件密码
var buffer = new byte[4096]; //缓冲区大小
var entry = new ZipEntry(Path.GetFileName(file)) { DateTime = DateTime.Now };
s.PutNextEntry(entry);
using (var fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
s.Finish();
s.Close();
}
}
catch (System.Exception ex)
{
blnResult = false;
throw new System.Exception(string.Format("压缩文件{0}时出现异常:{1}", file, ex));
}
return blnResult;
}
/// <summary>
/// Zips the specified zip path.
/// </summary>
后面还有 132 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。