C# ZipHelper C#公共类 -- ZipArchive实现压缩和解压
从网上找来个ZipArchive来压缩和解压缩的类,供参考吧
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Shared; namespace Helpers
{
public static class ZipFileHelper {
#region Methods /// <summary>
/// 创建 zip 存档,该存档包含指定目录的文件和目录。
/// </summary>
/// <param name="sourceDirectoryName">要存档的目录的路径,指定为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="destinationArchiveFileName">要生成的存档路径,指定为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="compressionLevel"></param>
/// <param name="includeBaseDirectory">压缩包中是否包含父目录</param>
public static bool CreatZipFileFromDirectory(string sourceDirectoryName, string destinationArchiveFileName,
CompressionLevel compressionLevel = CompressionLevel.NoCompression,
bool includeBaseDirectory = true)
{
try
{
if (Directory.Exists(sourceDirectoryName)) //目录
if (!File.Exists(destinationArchiveFileName))
{
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName,
compressionLevel, includeBaseDirectory);
}
else
{
var toZipFileDictionaryList = GetAllDirList(sourceDirectoryName, includeBaseDirectory); using (
var archive = ZipFile.Open(destinationArchiveFileName, ZipArchiveMode.Update)
)
{
foreach (var toZipFileKey in toZipFileDictionaryList.Keys)
if (toZipFileKey != destinationArchiveFileName)
{
var toZipedFileName = Path.GetFileName(toZipFileKey);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
if (toZipedFileName != null &&
(zipArchiveEntry.FullName.StartsWith(toZipedFileName) ||
toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
toDelArchives.Add(zipArchiveEntry);
foreach (var zipArchiveEntry in toDelArchives)
zipArchiveEntry.Delete();
archive.CreateEntryFromFile(toZipFileKey, toZipFileDictionaryList[toZipFileKey],
compressionLevel);
}
}
}
else if (File.Exists(sourceDirectoryName))
if (!File.Exists(destinationArchiveFileName))
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName,
compressionLevel, false);
else
using (
var archive = ZipFile.Open(destinationArchiveFileName, ZipArchiveMode.Update)
)
{
if (sourceDirectoryName != destinationArchiveFileName)
{
var toZipedFileName = Path.GetFileName(sourceDirectoryName);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
if (toZipedFileName != null &&
(zipArchiveEntry.FullName.StartsWith(toZipedFileName) ||
toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
toDelArchives.Add(zipArchiveEntry);
foreach (var zipArchiveEntry in toDelArchives)
zipArchiveEntry.Delete();
archive.CreateEntryFromFile(sourceDirectoryName, toZipedFileName, compressionLevel);
}
}
else
return false;
return true;
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
MessageBox.Show(exception.StackTrace, exception.Source);
return false;
}
} /// <summary>
/// 创建 zip 存档,该存档包含指定目录的文件和目录。
/// </summary>
/// <param name="sourceDirectoryName">要存档的目录的路径,指定为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="destinationArchiveFileName">要生成的存档路径,指定为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="compressionLevel"></param>
public static bool CreatZipFileFromDictionary(Dictionary<string, string> sourceDirectoryName,
string destinationArchiveFileName,
CompressionLevel compressionLevel = CompressionLevel.NoCompression)
{
try
{
using (FileStream zipToOpen = new FileStream(destinationArchiveFileName, FileMode.OpenOrCreate))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
foreach (var toZipFileKey in sourceDirectoryName.Keys)
if (toZipFileKey != destinationArchiveFileName)
{
var toZipedFileName = Path.GetFileName(toZipFileKey);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
if (toZipedFileName != null &&
(zipArchiveEntry.FullName.StartsWith(toZipedFileName) ||
toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
toDelArchives.Add(zipArchiveEntry);
foreach (var zipArchiveEntry in toDelArchives)
zipArchiveEntry.Delete();
archive.CreateEntryFromFile(toZipFileKey, sourceDirectoryName[toZipFileKey],
compressionLevel);
}
}
}
return true;
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
MessageBox.Show(exception.StackTrace, exception.Source);
return false;
}
} /// <summary>
/// 递归删除文件夹目录及文件
/// </summary>
/// <param name="baseDirectory"></param>
/// <returns></returns>
public static bool DeleteFolder(string baseDirectory)
{
var successed = true;
try
{
if (Directory.Exists(baseDirectory)) //如果存在这个文件夹删除之
{
foreach (var directory in Directory.GetFileSystemEntries(baseDirectory))
if (File.Exists(directory))
File.Delete(directory); //直接删除其中的文件
else
successed = DeleteFolder(directory); //递归删除子文件夹
Directory.Delete(baseDirectory); //删除已空文件夹
}
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
successed = false;
}
return successed;
} /// <summary>
/// 调用bat删除目录,以防止系统底层的异步删除机制
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
public static bool DeleteDirectoryWithCmd(string dirPath)
{
var process = new Process(); //string path = ...;//bat路径
var processStartInfo = new ProcessStartInfo("CMD.EXE", "/C rd /S /Q \"" + dirPath + "\"")
{
UseShellExecute = false,
RedirectStandardOutput = true
}; //第二个参数为传入的参数,string类型以空格分隔各个参数
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
if (string.IsNullOrWhiteSpace(output))
return true;
return false;
} /// <summary>
/// 调用bat删除文件,以防止系统底层的异步删除机制
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static bool DelFileWithCmd(string filePath)
{
var process = new Process(); //string path = ...;//bat路径
var processStartInfo = new ProcessStartInfo("CMD.EXE", "/C del /F /S /Q \"" + filePath + "\"")
{
UseShellExecute = false,
RedirectStandardOutput = true
}; //第二个参数为传入的参数,string类型以空格分隔各个参数
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
if (output.Contains(filePath))
return true;
return false;
} /// <summary>
/// 获取目录下所有[文件名,要压缩的相对文件名]字典
/// </summary>
/// <param name="strBaseDir"></param>
/// <param name="includeBaseDirectory"></param>
/// <param name="namePrefix"></param>
/// <returns></returns>
public static Dictionary<string, string> GetAllDirList(string strBaseDir,
bool includeBaseDirectory = false, string namePrefix = "")
{
var resultDictionary = new Dictionary<string, string>();
var directoryInfo = new DirectoryInfo(strBaseDir);
var directories = directoryInfo.GetDirectories();
var fileInfos = directoryInfo.GetFiles();
if (includeBaseDirectory)
namePrefix += directoryInfo.Name + "\\";
foreach (var directory in directories)
resultDictionary =
resultDictionary.Concat(GetAllDirList(directory.FullName, true, namePrefix))
.ToDictionary(k => k.Key, k => k.Value); //.FullName是某个子目录的绝对地址,
foreach (var fileInfo in fileInfos)
if (!resultDictionary.ContainsKey(fileInfo.FullName))
resultDictionary.Add(fileInfo.FullName, namePrefix + fileInfo.Name);
return resultDictionary;
} /// <summary>
/// Zip解压并更新目标文件
/// </summary>
/// <param name="zipFilePath">Zip压缩包路径</param>
/// <param name="unZipDir">解压目标路径</param>
/// <returns></returns>
public static bool UnZip(string zipFilePath, string unZipDir)
{
bool resualt;
try
{
unZipDir = unZipDir.EndsWith(@"\") ? unZipDir : unZipDir + @"\";
var directoryInfo = new DirectoryInfo(unZipDir);
if (!directoryInfo.Exists)
directoryInfo.Create();
var fileInfo = new FileInfo(zipFilePath);
if (!fileInfo.Exists)
return false;
using (
var zipToOpen = new FileStream(zipFilePath, FileMode.Open, FileAccess.ReadWrite,
FileShare.Read))
{
using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
{
foreach (var zipArchiveEntry in archive.Entries)
if (!zipArchiveEntry.FullName.EndsWith("/"))
{
var entryFilePath = Regex.Replace(zipArchiveEntry.FullName.Replace("/", @"\"),
@"^\\*", "");
var filePath = directoryInfo + entryFilePath; //设置解压路径
var content = new byte[zipArchiveEntry.Length];
zipArchiveEntry.Open().Read(content, , content.Length); if (File.Exists(filePath) && content.Length == new FileInfo(filePath).Length)
continue; //跳过相同的文件,否则覆盖更新 var sameDirectoryNameFilePath = new DirectoryInfo(filePath);
if (sameDirectoryNameFilePath.Exists)
{
sameDirectoryNameFilePath.Delete(true);
DeleteDirectoryWithCmd(filePath);
/*if (!DeleteDirectoryWithCmd(filePath))
{
Console.WriteLine(filePath + "删除失败");
resualt = false;
break;
}*/
}
var sameFileNameFilePath = new FileInfo(filePath);
if (sameFileNameFilePath.Exists)
{
sameFileNameFilePath.Delete();
DelFileWithCmd(filePath);
/*if (!DelFileWithCmd(filePath))
{
Console.WriteLine(filePath + "删除失败");
resualt = false;
break;
}*/
}
var greatFolder = Directory.GetParent(filePath);
if (!greatFolder.Exists) greatFolder.Create();
File.WriteAllBytes(filePath, content);
}
}
}
resualt = true;
}
catch
(Exception exception)
{
LogHelper.LogError("Error! ", exception);
resualt = false;
}
return resualt;
} #endregion
}
}
出处:https://www.cnblogs.com/Chary/p/No0000DF.html
==============================================
自己在项目中的使用:
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Windows.Forms; namespace Car.AutoUpdate.Comm
{
public class ZipArchiveHelper
{ #region Methods /// <summary>
/// 创建 zip 存档,该文档包含指定目录的文件和子目录。
/// </summary>
/// <param name="sourceDirectoryName">将要压缩存档的文件目录的路径,可以为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="destinationArchiveFileName">将要生成的压缩包的存档路径,可以为相对路径或绝对路径。相对路径是指相对于当前工作目录的路径。</param>
/// <param name="compressionLevel">指示压缩操作是强调速度还是强调压缩大小的枚举值</param>
/// <param name="includeBaseDirectory">压缩包中是否包含父目录</param>
public static bool CreatZip(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel = CompressionLevel.NoCompression, bool includeBaseDirectory = true)
{
try
{
if (Directory.Exists(sourceDirectoryName))
if (!File.Exists(destinationArchiveFileName))
{
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, compressionLevel, includeBaseDirectory);
}
else
{
var toZipFileDictionaryList = GetAllDirList(sourceDirectoryName, includeBaseDirectory);
using (var archive = ZipFile.Open(destinationArchiveFileName, ZipArchiveMode.Update))
{
foreach (var toZipFileKey in toZipFileDictionaryList.Keys)
if (toZipFileKey != destinationArchiveFileName)
{
var toZipedFileName = Path.GetFileName(toZipFileKey);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
if (toZipedFileName != null && (zipArchiveEntry.FullName.StartsWith(toZipedFileName) || toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
toDelArchives.Add(zipArchiveEntry);
foreach (var zipArchiveEntry in toDelArchives)
zipArchiveEntry.Delete();
archive.CreateEntryFromFile(toZipFileKey, toZipFileDictionaryList[toZipFileKey], compressionLevel);
}
}
}
else if (File.Exists(sourceDirectoryName))
if (!File.Exists(destinationArchiveFileName))
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, compressionLevel, false);
else
using (var archive = ZipFile.Open(destinationArchiveFileName, ZipArchiveMode.Update))
{
if (sourceDirectoryName != destinationArchiveFileName)
{
var toZipedFileName = Path.GetFileName(sourceDirectoryName);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
if (toZipedFileName != null && (zipArchiveEntry.FullName.StartsWith(toZipedFileName) || toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
toDelArchives.Add(zipArchiveEntry);
foreach (var zipArchiveEntry in toDelArchives)
zipArchiveEntry.Delete();
archive.CreateEntryFromFile(sourceDirectoryName, toZipedFileName, compressionLevel);
}
}
else
return false;
return true;
}
catch (Exception ex)
{
LogHelper.Error("Error! ", ex);
//MessageBox.Show(ex.StackTrace, ex.Source);
UtilityHelper.ShowMessageDialog(ex.StackTrace);
return false;
}
} /// <summary>
/// 创建 zip 存档,该存档包含指定目录的文件和目录。
/// </summary>
/// <param name="sourceDirectoryName">将要压缩存档的文件目录的路径,可以为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="destinationArchiveFileName">将要生成的压缩包的存档路径,可以为相对路径或绝对路径。 相对路径是指相对于当前工作目录的路径。</param>
/// <param name="compressionLevel">指示压缩操作是强调速度还是强调压缩大小的枚举值</param>
public static bool CreatZip(Dictionary<string, string> sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel = CompressionLevel.NoCompression)
{
try
{
using (FileStream zipToOpen = new FileStream(destinationArchiveFileName, FileMode.OpenOrCreate))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
foreach (var toZipFileKey in sourceDirectoryName.Keys)
if (toZipFileKey != destinationArchiveFileName)
{
var toZipedFileName = Path.GetFileName(toZipFileKey);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
if (toZipedFileName != null && (zipArchiveEntry.FullName.StartsWith(toZipedFileName) || toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
toDelArchives.Add(zipArchiveEntry);
foreach (var zipArchiveEntry in toDelArchives)
zipArchiveEntry.Delete();
archive.CreateEntryFromFile(toZipFileKey, sourceDirectoryName[toZipFileKey], compressionLevel);
}
}
}
return true;
}
catch (Exception ex)
{
LogHelper.Error("Error! ", ex);
UtilityHelper.ShowMessageDialog(ex.StackTrace);
return false;
}
} /// <summary>
/// 递归删除磁盘上的指定文件夹目录及文件
/// </summary>
/// <param name="baseDirectory"></param>
/// <returns></returns>
private static bool DeleteFolder(string baseDirectory)
{
var successed = true;
try
{
if (Directory.Exists(baseDirectory)) //如果存在这个文件夹删除之
{
foreach (var directory in Directory.GetFileSystemEntries(baseDirectory))
if (File.Exists(directory))
File.Delete(directory); //直接删除其中的文件
else
successed = DeleteFolder(directory); //递归删除子文件夹
Directory.Delete(baseDirectory); //删除已空文件夹
}
}
catch (Exception ex)
{
LogHelper.Error("Error! ", ex);
successed = false;
}
return successed;
} /// <summary>
/// 调用CMD,命令行删除磁盘上的指定目录,以防止系统底层的异步删除机制
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
private static bool DeleteDirectoryWithCmd(string dirPath)
{
var process = new Process();
//ProcessStartInfo构造方法的第二个参数是执行第一个命令的所需要传入的参数,以空格分隔各个参数
var processStartInfo = new ProcessStartInfo("CMD.EXE", "/C rd /S /Q \"" + dirPath + "\"") { UseShellExecute = false, RedirectStandardOutput = true };
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
if (string.IsNullOrWhiteSpace(output))
return true;
return false;
} /// <summary>
/// 调用CMD,命令行删除磁盘上的指定目录,以防止系统底层的异步删除机制
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
private static bool DelFileWithCmd(string filePath)
{
var process = new Process();
//ProcessStartInfo构造方法的第二个参数是执行第一个命令的所需要传入的参数,以空格分隔各个参数
var processStartInfo = new ProcessStartInfo("CMD.EXE", "/C del /F /S /Q \"" + filePath + "\"") { UseShellExecute = false, RedirectStandardOutput = true };
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
if (output.Contains(filePath))
return true;
return false;
} /// <summary>
/// 递归获取磁盘上的指定目录下所有文件的集合,返回类型是:字典[文件名,要压缩的相对文件名]
/// </summary>
/// <param name="strBaseDir"></param>
/// <param name="includeBaseDirectory"></param>
/// <param name="namePrefix"></param>
/// <returns></returns>
private static Dictionary<string, string> GetAllDirList(string strBaseDir, bool includeBaseDirectory = false, string namePrefix = "")
{
var resultDictionary = new Dictionary<string, string>();
var directoryInfo = new DirectoryInfo(strBaseDir);
var directories = directoryInfo.GetDirectories();
var fileInfos = directoryInfo.GetFiles();
if (includeBaseDirectory)
namePrefix += directoryInfo.Name + "\\";
foreach (var directory in directories)
resultDictionary = resultDictionary.Concat(GetAllDirList(directory.FullName, true, namePrefix)).ToDictionary(k => k.Key, k => k.Value); //FullName是某个子目录的绝对地址,
foreach (var fileInfo in fileInfos)
if (!resultDictionary.ContainsKey(fileInfo.FullName))
resultDictionary.Add(fileInfo.FullName, namePrefix + fileInfo.Name);
return resultDictionary;
} /// <summary>
/// 解压Zip文件,并覆盖保存到指定的目标路径文件夹下
/// </summary>
/// <param name="zipFilePath">将要解压缩的zip文件的路径</param>
/// <param name="unZipDir">解压后将zip中的文件存储到磁盘的目标路径</param>
/// <returns></returns>
public static bool UnZip(string zipFilePath, string unZipDir)
{
bool resualt;
try
{
unZipDir = unZipDir.EndsWith(@"\") ? unZipDir : unZipDir + @"\";
var directoryInfo = new DirectoryInfo(unZipDir);
if (!directoryInfo.Exists)
directoryInfo.Create();
var fileInfo = new FileInfo(zipFilePath);
if (!fileInfo.Exists)
return false;
using (var zipToOpen = new FileStream(zipFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
{
using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
{
foreach (var zipArchiveEntry in archive.Entries)
if (!zipArchiveEntry.FullName.EndsWith("/"))
{
var entryFilePath = Regex.Replace(zipArchiveEntry.FullName.Replace("/", @"\"), @"^\\*", "");
var filePath = directoryInfo + entryFilePath; //设置解压路径
var content = new byte[zipArchiveEntry.Length];
zipArchiveEntry.Open().Read(content, , content.Length); // mq 2019-06-14: 注销下面的代码,全部覆盖现有文件
//if (File.Exists(filePath) && content.Length == new FileInfo(filePath).Length)
//{
// continue; //跳过相同的文件,否则覆盖更新
//}
//var sameDirectoryNameFilePath = new DirectoryInfo(filePath);
//if (sameDirectoryNameFilePath.Exists)
//{
// sameDirectoryNameFilePath.Delete(true);
// DeleteDirectoryWithCmd(filePath);
//}
//var sameFileNameFilePath = new FileInfo(filePath);
//if (sameFileNameFilePath.Exists)
//{
// sameFileNameFilePath.Delete();
// DelFileWithCmd(filePath);
// /*if (!DelFileWithCmd(filePath))
// {
// Console.WriteLine(filePath + "删除失败");
// resualt = false;
// break;
// }*/
//} var greatFolder = Directory.GetParent(filePath);
if (!greatFolder.Exists)
greatFolder.Create();
File.WriteAllBytes(filePath, content);
}
}
}
resualt = true;
}
catch (Exception ex)
{
LogHelper.Error("Error! ", ex);
resualt = false;
}
return resualt;
} /// <summary>
/// 获取Zip压缩包中的文件列表
/// </summary>
/// <param name="zipFilePath">Zip压缩包文件的物理路径</param>
/// <returns></returns>
public static List<string> GetZipFileList(string zipFilePath)
{
List<string> fList = new List<string>();
if (!File.Exists(zipFilePath))
return fList;
try
{
using (var zipToOpen = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
{
foreach (var zipArchiveEntry in archive.Entries)
if (!zipArchiveEntry.FullName.EndsWith("/"))
fList.Add(Regex.Replace(zipArchiveEntry.FullName.Replace("/", @"\"), @"^\\*", ""));
}
}
}
catch (Exception ex)
{
LogHelper.Error("Error! ", ex);
}
return fList;
} #endregion
}
}
C# ZipHelper C#公共类 -- ZipArchive实现压缩和解压的更多相关文章
- PHP扩展类ZipArchive实现压缩解压Zip文件和文件打包下载
文章转载自:https://my.oschina.net/junn/blog/104464 PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PH ...
- PHP扩展类ZipArchive实现压缩解压Zip文件和文件打包下载 && Linux下的ZipArchive配置开启压缩 &&搞个鸡巴毛,写少了个‘/’号,浪费了一天
PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启,具体开启方法就不说了,不同的平台开启PHP扩增的方法网上都有,如有 ...
- ZipHelper 压缩和解压帮助类
ZipHelper 压缩和解压帮助类 关于本文档的说明 本文档基于ICSharpCode.SharpZipLib.dll的封装,常用的解压和压缩方法都已经涵盖在内,都是经过项目实战积累下来的 欢迎传播 ...
- 【C#公共帮助类】WinRarHelper帮助类,实现文件或文件夹压缩和解压,实战干货
关于本文档的说明 本文档使用WinRAR方式来进行简单的压缩和解压动作,纯干货,实际项目这种压缩方式用的少一点,一般我会使用第三方的压缩dll来实现,就如同我上一个压缩类博客,压缩的是zip文件htt ...
- c#自带压缩类实现的多文件压缩和解压
用c#自带的System.IO.Compression命名空间下的压缩类实现的多文件压缩和解压功能,缺点是多文件压缩包的解压只能调用自身的解压方法,和现有的压缩软件不兼容.下面的代码没有把多文件的目录 ...
- 利用c#自带的类对文件进行压缩和解压处理
在做网络传输文件的小例子的时候,当传输的文件比较大的时候,我们通常都是将文件经过压缩之后才进行传输,以前都是利用第三方插件来对文件进行压缩的,但是现在我发现了c#自带的类库也能够实现文件的压缩,实际上 ...
- Linux 时间日期类、搜索查找类、 压缩和解压类指令
l 时间日期类 date指令-显示当前日期 基本语法 1) date (功能描述:显示当前时间) 2) date +%Y (功能描述:显示当前年份) 3) date +%m (功能描述:显示当前月份) ...
- Linux时间日期类,压缩和解压类
一.时间日期类 1.data指令 1.基本指令 date 显示当前日期 data +%Y 显示当前年份 data +%m 显示当前月份 data +%d 显示当前天 data +%Y-%m-%d %H ...
- 【转】Java压缩和解压文件工具类ZipUtil
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
随机推荐
- synchronized同步方法《二》
1.synchronized方法和锁对象 (1).验证线程锁的是对象 代码如下: 1.1创建一个MyObject类: package edu.ymm.about_thread4; public cla ...
- Coding daily
@2017-7月 1可视化控件的awakeFromNib不调用? 因为用代码注册了cell 2scrollView添加子控件布局无效? 最好不要用masonry,直接用frame 还有tableVie ...
- Web版记账本开发记录(四)
今天已经是是开发软件的第四天了,今天遇到了一些简单的小问题,虽然简单,但是自己仍旧不具备修改的能力, 自己尝试了各种办法仍旧没有修改成功,在收入表就状况百出,错误不断. 我决定明天还是静下心来好好地学 ...
- Putting Boxes Together CodeForces - 1030F (带权中位数)
#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> ...
- icpc2018-焦作-E Resistors in Parallel-数论+大数
http://codeforces.com/gym/102028/problem/E 定义n种电阻,阻值r[i]={ inf | i%d2==0 && d>1 , i | e ...
- Linux下输入某些命令时会提示:bash:command not found
首先,查看$PATH中是否包含了这些命令. $PATH:决定了shell到哪些目录中去寻找命令或程序,PATH值是一系列的目录.当运行程序时,linux到这些目录下搜索进行编译链接. 格式: PATH ...
- 5、Angular的一些其他核心特性,学习的主要模块
Angular应用程序的八个主要构造块: 模块 组件 模板 元数据 数据绑定 指令 服务 依赖注入 其他重要的Angular特性和服务: 动画 表单 HTTP 组件生命周期 管道过滤器 路由 测试
- systemctl用法及其语法
1.确定是否安装systemd及其版本 # systemctl –version 2.确定systemd和systemctl的二进制文件和库文件的安装位置 # whereis systemd # wh ...
- 微信小程序中对于变量的定义
在页面对应的js文件中: page顶部使用let定义变量,这是定义的全局变量,在当前脚本页面,任何函数中都可以直接使用变量名调用.如果做修改,就直接使用变量等于要更改的值. 使用const定义变量,就 ...
- Python *Mix_w8
文件操作的函数 文件可迭代 open(文件名(路径), mode="?", encoding="字符集") f = open("../Python/是 ...