推薦:關(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 所寫的代碼。
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();
}
}
分享:MVC4 基礎(chǔ) 枚舉生成 DropDownList 實(shí)用技巧本篇文章小編為大家介紹,MVC4 基礎(chǔ) 枚舉生成 DropDownList 實(shí)用技巧。需要的朋友參考下
新聞熱點(diǎn)
疑難解答
圖片精選