6月iOS設備好評榜:第一蟬聯榜首近一年
作為安兔兔各種榜單里變化最小的那個,2023年6月的iOS好評榜和上個月相比沒有任何排名上的變化,僅僅是部分設備好評率的下降,長年累月的用戶評價和逐漸退出市場的老款機器讓這
using System;using ICSharpCode.SharpZipLib.Zip;class Program{ static void Main() { string sourceFolder = @"C:/Path/To/Your/Folder"; string zipFile = @"C:/Path/To/Your/Archive.zip"; ZipDirectory(sourceFolder, zipFile); Console.WriteLine("Compression completed."); string extractFolder = @"C:/Path/To/Your/Extracted"; UnzipFile(zipFile, extractFolder); Console.WriteLine("Extraction completed."); } static void ZipDirectory(string sourceFolder, string zipFile) { using (ZipOutputStream zipStream = new ZipOutputStream(System.IO.File.Create(zipFile))) { zipStream.SetLevel(9); // 0 - store only to 9 - means best compression ZipFolder(sourceFolder, sourceFolder, zipStream); zipStream.Finish(); zipStream.Close(); } } static void ZipFolder(string rootFolder, string currentFolder, ZipOutputStream zipStream) { string[] files = System.IO.Directory.GetFiles(currentFolder); foreach (string file in files) { ZipFile(zipStream, currentFolder, file); } string[] subFolders = System.IO.Directory.GetDirectories(currentFolder); foreach (string folder in subFolders) { ZipFolder(rootFolder, folder, zipStream); } } static void ZipFile(ZipOutputStream zipStream, string rootFolder, string filePath) { byte[] buffer = new byte[4096]; string relativePath = filePath.Substring(rootFolder.Length + 1); ZipEntry entry = new ZipEntry(relativePath); zipStream.PutNextEntry(entry); using (System.IO.FileStream fs = System.IO.File.OpenRead(filePath)) { int sourceBytes; do { sourceBytes = fs.Read(buffer, 0, buffer.Length); zipStream.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); } } static void UnzipFile(string zipFile, string extractFolder) { using (ZipInputStream zipStream = new ZipInputStream(System.IO.File.OpenRead(zipFile))) { ZipEntry entry; while ((entry = zipStream.GetNextEntry()) != null) { string entryName = entry.Name; string fullZipToPath = System.IO.Path.Combine(extractFolder, entryName); string directoryName = System.IO.Path.GetDirectoryName(fullZipToPath); if (directoryName.Length > 0) { System.IO.Directory.CreateDirectory(directoryName); } if (entry.IsFile) { byte[] buffer = new byte[4096]; using (System.IO.FileStream streamWriter = System.IO.File.Create(fullZipToPath)) { int sourceBytes; do { sourceBytes = zipStream.Read(buffer, 0, buffer.Length); streamWriter.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); } } } } }}
using System;using Ionic.Zip;class Program{ static void Main() { string sourceFolder = @"C:/Path/To/Your/Folder"; string zipFile = @"C:/Path/To/Your/Archive.zip"; ZipDirectory(sourceFolder, zipFile); Console.WriteLine("Compression completed."); string extractFolder = @"C:/Path/To/Your/Extracted"; UnzipFile(zipFile, extractFolder); Console.WriteLine("Extraction completed."); } static void ZipDirectory(string sourceFolder, string zipFile) { using (ZipFile zip = new ZipFile()) { zip.AddDirectory(sourceFolder); zip.Save(zipFile); } } static void UnzipFile(string zipFile, string extractFolder) { using (ZipFile zip = ZipFile.Read(zipFile)) { zip.ExtractAll(extractFolder, ExtractExistingFileAction.OverwriteSilently); } }}
以上兩個例子都提供了基本的目錄壓縮和解壓縮功能,你可以根據具體需求進行進一步定制。確保在實際項目中進行充分的測試和適當的錯誤處理。
本文鏈接:http://www.www897cc.com/showinfo-26-78147-0.html搞懂C#文件壓縮:SharpZipLib vs. DotNetZip,實用代碼一網打盡!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com