在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在.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) 使用.NET FrameWork 4.5中自带的压缩。 复制代码 代码如下: static void Main(string[] args) { Stopwatch watch = new Stopwatch(); watch.Start(); string path = @"E:\"; Compress(path, @"F:\4.5.zip"); watch.Stop(); Console.WriteLine("消耗时间:{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); } 怎么样代码是不是简洁了很多呢? |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论