C#压缩解压帮助类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using ICSharpCode.SharpZipLib.Zip; namespace GzRMIS.Main.Business { public class ZipHelper { /// <summary> /// 存放待压缩的文件的绝对路径 /// </summary> private List<string> AbsolutePaths { set; get; } public string errorMsg { set; get; } public ZipHelper() { errorMsg = ""; AbsolutePaths = new List<string>(); } /// <summary> /// 添加压缩文件或文件夹 /// </summary> /// <param name="_fileAbsolutePath">文件或文件夹的绝对路径</param> public void AddFile(string _fileAbsolutePath) { AbsolutePaths.Add(_fileAbsolutePath); } /// <summary> /// 压缩文件或者文件夹 /// </summary> /// <param name="_depositPath">压缩后文件的存放路径 如C:\\windows\abc.zip</param> /// <param name="_Level">压缩级别0~9,数字越大压缩率越高,默认为5</param> /// <returns></returns> public bool CompressionZip(string _depositPath,int _Level=5) { bool result = true; FileStream fs = null; try { ZipOutputStream ComStream = new ZipOutputStream(File.Create(_depositPath)); ComStream.SetLevel(_Level); //压缩等级 foreach (string path in AbsolutePaths) { //如果是目录 if (Directory.Exists(path)) { ZipFloder(path, ComStream, path); } else if (File.Exists(path))//如果是文件 { fs = File.OpenRead(path); byte[] bts = new byte[fs.Length]; fs.Read(bts, 0, bts.Length); ZipEntry ze = new ZipEntry(new FileInfo(path).Name); ComStream.PutNextEntry(ze); //为压缩文件流提供一个容器 ComStream.Write(bts, 0, bts.Length); //写入字节 } } ComStream.Finish(); // 结束压缩 ComStream.Close(); } catch (Exception ex) { if (fs != null) { fs.Close(); } errorMsg = ex.Message; result = false; } return result; } //压缩文件夹 private void ZipFloder(string _OfloderPath, ZipOutputStream zos, string _floderPath) { foreach (FileSystemInfo item in new DirectoryInfo(_floderPath).GetFileSystemInfos()) { if (Directory.Exists(item.FullName)) { ZipFloder(_OfloderPath, zos, item.FullName); } else if (File.Exists(item.FullName))//如果是文件 { DirectoryInfo ODir = new DirectoryInfo(_OfloderPath); string fullName2 = new FileInfo(item.FullName).FullName; string path = ODir.Name + fullName2.Substring(ODir.FullName.Length, fullName2.Length - ODir.FullName.Length);//获取相对目录 FileStream fs = File.OpenRead(fullName2); byte[] bts = new byte[fs.Length]; fs.Read(bts, 0, bts.Length); ZipEntry ze = new ZipEntry(path); zos.PutNextEntry(ze); //为压缩文件流提供一个容器 zos.Write(bts, 0, bts.Length); //写入字节 } } } /// <summary> /// 解压 /// </summary> /// <param name="_depositPath">压缩文件路径</param> /// <param name="_floderPath">解压的路径</param> /// <returns></returns> public bool DeCompressionZip(string _depositPath, string _floderPath) { bool result = true; FileStream fs = null; try { ZipInputStream InpStream = new ZipInputStream(File.OpenRead(_depositPath)); ZipEntry ze = InpStream.GetNextEntry();//获取压缩文件中的每一个文件 Directory.CreateDirectory(_floderPath);//创建解压文件夹 while (ze != null)//如果解压完ze则是null { if (ze.IsFile)//压缩zipINputStream里面存的都是文件。带文件夹的文件名字是文件夹\\文件名 { string[] strs = ze.Name.Split('\\');//如果文件名中包含’\\‘则表明有文件夹 if (strs.Length > 1) { //两层循环用于一层一层创建文件夹 for (int i = 0; i < strs.Length - 1; i++) { string floderPath = _floderPath; for (int j = 0; j < i; j++) { floderPath = floderPath + "\\" + strs[j]; } floderPath = floderPath + "\\" + strs[i]; Directory.CreateDirectory(floderPath); } } fs = new FileStream(_floderPath + "\\" + ze.Name, FileMode.OpenOrCreate, FileAccess.Write);//创建文件 //循环读取文件到文件流中 while (true) { byte[] bts = new byte[1024]; int i = InpStream.Read(bts, 0, bts.Length); if (i > 0) { fs.Write(bts, 0, i); } else { fs.Flush(); fs.Close(); break; } } } ze = InpStream.GetNextEntry(); } } catch (Exception ex) { if (fs != null) { fs.Close(); } errorMsg = ex.Message; result = false; } return result; } } }

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

C#.NET依然重要,因为它提供了强大的工具和库,支持多种应用开发。1)C#结合.NET框架,使开发高效便捷。2)C#的类型安全和垃圾回收机制增强了其优势。3).NET提供跨平台运行环境和丰富的API,提升了开发灵活性。

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C#在企业级应用、游戏开发、移动应用和Web开发中均有广泛应用。1)在企业级应用中,C#常用于ASP.NETCore开发WebAPI。2)在游戏开发中,C#与Unity引擎结合,实现角色控制等功能。3)C#支持多态性和异步编程,提高代码灵活性和应用性能。

C#和.NET通过不断的更新和优化,适应了新兴技术的需求。1)C#9.0和.NET5引入了记录类型和性能优化。2).NETCore增强了云原生和容器化支持。3)ASP.NETCore与现代Web技术集成。4)ML.NET支持机器学习和人工智能。5)异步编程和最佳实践提升了性能。

如何将C#.NET应用部署到Azure或AWS?答案是使用AzureAppService和AWSElasticBeanstalk。1.在Azure上,使用AzureAppService和AzurePipelines自动化部署。2.在AWS上,使用AmazonElasticBeanstalk和AWSLambda实现部署和无服务器计算。

C#和.NET运行时紧密合作,赋予开发者高效、强大且跨平台的开发能力。1)C#是一种类型安全且面向对象的编程语言,旨在与.NET框架无缝集成。2).NET运行时管理C#代码的执行,提供垃圾回收、类型安全等服务,确保高效和跨平台运行。

C#和.NET的关系是密不可分的,但它们不是一回事。C#是一门编程语言,而.NET是一个开发平台。C#用于编写代码,编译成.NET的中间语言(IL),由.NET运行时(CLR)执行。

要开始C#.NET开发,你需要:1.了解C#的基础知识和.NET框架的核心概念;2.掌握变量、数据类型、控制结构、函数和类的基本概念;3.学习C#的高级特性,如LINQ和异步编程;4.熟悉常见错误的调试技巧和性能优化方法。通过这些步骤,你可以逐步深入C#.NET的世界,并编写高效的应用程序。
