翻譯|使用教程|編輯:李顯亮|2021-04-21 10:49:38.387|閱讀 252 次
概述:我們可以將多個文件以壓縮形式存儲為RAR存檔。在本文中,將學習如何從壓縮的RAR存檔中解壓縮文件或提取文件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
ZIP檔案是用來壓縮和保持一個或多個文件或文件夾到一個單一的容器中。ZIP歸檔文件封裝了文件和文件夾,并保存了它們的元數據信息。歸檔的最常見用法是減小用于存儲或傳輸的文件的大小,并應用加密以提高安全性。
Aspose.ZIP for .NET是用于標準ZIP格式的靈活文檔壓縮和存檔操作API。API使.NET應用程序能夠實現文件壓縮/解壓縮,文件存檔以及文件夾和存檔加密。
您可以將多個文件以壓縮形式存儲為RAR存檔。在本文中,將學習如何從壓縮的RAR存檔中解壓縮文件或提取文件。請在以下部分中找到更多詳細信息:
Aspose.Zip for .NETAPI支持從壓縮格式(如RAR,ZIP,7Z等)存檔和提取文件。如果你還沒有用過Aspose.Zip,可以點擊這里下載最新版測試。
可以按照以下步驟從RAR歸檔文件中解壓縮或提取特定文件:
以下代碼顯示了如何使用C#以編程方式從RAR存檔中解壓縮或提取特定文件:
// Load input RAR file. using (RarArchive archive = new RarArchive("Sample.rar")) { // Create a file with Create() method. using (var destination = File.Create("Extracted_File1.txt")) { // Open an entry from the RAR archive. using (var source = archive.Entries[0].Open()) { byte[] buffer = new byte[1024]; int bytesRead; // Write extracted data to the file. while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0) destination.Write(buffer, 0, bytesRead); } } }
可以按照以下步驟從RAR歸檔文件中解壓縮或提取所有文件:
以下代碼顯示了如何使用C#以編程方式從RAR存檔中解壓縮所有文件:
// Load input RAR file. RarArchive archive = new RarArchive("Sample.rar"); // Unrar or extract all files from the archive archive.ExtractToDirectory("extracted");
可以按照以下步驟從受密碼保護的RAR存檔中解壓縮特定文件:
以下代碼說明了如何使用C#從受密碼保護或加密的存檔中解壓縮特定文件:
// Load the RAR file Encypted with Password. FileInfo fi = new FileInfo("Data_Password.rar"); using (RarArchive archive = new RarArchive(fi.OpenRead())) { // Specify file name for the output file. using (FileStream destination = File.Create("Password_Extracted_File1.txt")) { // Extract the password protected file. archive.Entries[0].Extract(destination, "Aspose"); } }
可以按照以下步驟從密碼加密的RAR存檔中提取所有文件:
以下代碼段顯示了如何使用C#以編程方式從密碼加密的RAR文件中解壓縮所有文件:
// Load an encrypted RAR file RarArchive archive = new RarArchive("Data_Password.rar"); // Unrar or extract password protected files from the archive // Specify password as String at second argument of method archive.ExtractToDirectory("PasswordExtracted" , "Aspose");
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn