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

首頁 > 編程 > .NET > 正文

基于.NET 4.5 壓縮的使用

2024-07-10 12:45:44
字體:
來源:轉載
供稿:網友

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

傳統使用ICSharpCode.SharpZipLib.dll 所寫的代碼。
代碼如下:
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("消耗時間:{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
                    {

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大化| 太和县| 南郑县| 绥芬河市| 陕西省| 恭城| 利辛县| 仙居县| 清涧县| 克山县| 台北市| 防城港市| 乌鲁木齐县| 志丹县| 永仁县| 阿瓦提县| 塘沽区| 天水市| 盐城市| 手游| 永川市| 宝兴县| 饶阳县| 乌兰县| 班戈县| 高清| 临沂市| 托克逊县| 潞西市| 威信县| 南澳县| 金沙县| 札达县| 昆明市| 富源县| 伽师县| 尚志市| 衡阳市| 贡嘎县| 深泽县| 黄骅市|