国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

基于.NET 4.5 壓縮的使用_.Net教程

2024-07-10 12:52:11
字體:
供稿:網(wǎng)友

推薦:關(guān)于VS2012自帶的 性能分析 工具使用實(shí)例(圖文介紹)
本篇文章小編為大家介紹,關(guān)于VS2012自帶的 性能分析 工具使用實(shí)例(圖文介紹),需要的朋友參考下

在.NET 4.5中新加入的壓縮的命名空間和方法。可以拋棄ICSharpCode.SharpZipLib.dll 這個(gè)類庫了。性能上不相上下。但是能夠大大簡(jiǎn)化你的代碼。如果開始使用.NET FrameWork4.5 做壓縮不妨試試自帶的壓縮方法.

傳統(tǒng)使用ICSharpCode.SharpZipLib.dll 所寫的代碼。

復(fù)制代碼 代碼如下:www.CuoXIn.com

static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
string path = @"E:/";
Compress(Directory.GetFiles(path), @"F:/4.0.zip");
watch.Stop();
Console.WriteLine("消耗時(shí)間:{0}", watch.ElapsedMilliseconds);
FileInfo f = new FileInfo(@"F:/4.0.zip");
Console.WriteLine("文件大小{0}", f.Length);
}

static void Compress(string[] filePaths, string zipFilePath)
{
byte[] _buffer = new byte[4096];
if (!Directory.Exists(zipFilePath))
Directory.CreateDirectory(Path.GetDirectoryName(zipFilePath));
using (ZipOutputStream zip = new ZipOutputStream(File.Create(zipFilePath)))
{
foreach (var item in filePaths)
{
if (!File.Exists(item))
{
Console.WriteLine("the file {0} not exist!", item);
}
else
{
ZipEntry entry = new ZipEntry(Path.GetFileName(item));
entry.DateTime = DateTime.Now;
zip.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(item))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(_buffer, 0, _buffer.Length);
zip.Write(_buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
}
zip.Finish();
zip.Close();
}
}


使用.NET FrameWork 4.5中自帶的壓縮。
復(fù)制代碼 代碼如下:www.CuoXIn.com

static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
string path = @"E:/";
Compress(path, @"F:/4.5.zip");
watch.Stop();
Console.WriteLine("消耗時(shí)間:{0}", watch.ElapsedMilliseconds);
FileInfo f = new FileInfo(@"F:/4.5.zip");
Console.WriteLine("文件大小{0}", f.Length);
}
static void Compress(string filePath, string zipFilePath)
{
ZipFile.CreateFromDirectory(filePath, zipFilePath, CompressionLevel.Fastest, false);
}

怎么樣代碼是不是簡(jiǎn)潔了很多呢?

分享:MVC4 基礎(chǔ) 枚舉生成 DropDownList 實(shí)用技巧
本篇文章小編為大家介紹,MVC4 基礎(chǔ) 枚舉生成 DropDownList 實(shí)用技巧。需要的朋友參考下

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 弥勒县| 图木舒克市| 准格尔旗| 开封市| 海兴县| 景泰县| 东源县| 芜湖县| 无锡市| 黄大仙区| 青冈县| 白银市| 民乐县| 宜兴市| 宜丰县| 胶南市| 克山县| 邵阳县| 陈巴尔虎旗| 孝感市| 广水市| 拜泉县| 依安县| 黑龙江省| 寿宁县| 九龙县| 个旧市| 凌海市| 通州区| 金秀| 彭山县| 蒙阴县| 巫溪县| 德庆县| 郁南县| 陇西县| 醴陵市| 中卫市| 泽库县| 台东县| 油尖旺区|