用C#压缩单个txt文件的最简单方式是什么

来源:百度知道 编辑:UC知道 时间:2024/06/08 11:33:54
有看到的是用第三方组件,不是道是不是很麻烦?……有没有更简单点的方法。3Q~

/**//// <summary>
/// 压缩文件
/// </summary>
/// <param name="FileToZip">要进行压缩的文件名</param>
/// <param name="ZipedFile">压缩后生成的压缩文件名</param>
/// <returns></returns>
private static bool ZipFile(string FileToZip, string ZipedFile, String Password)
{
//如果文件没有找到,则报错
if (!File.Exists(FileToZip))
{
throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
}
//FileStream fs = null;
FileStream ZipFile = null;
ZipOutputStream ZipStream = null;
ZipEntry ZipEntry = null;

bool res = true;
try
{
ZipFile = File.OpenRead(FileToZip);
byte[] buffer = new by