• C#解压缩


    /// <summary>  
            /// 解压缩文件(压缩文件中含有子目录)  
            /// </summary>  
            /// <param name="zipfilepath">待解压缩的文件路径</param>  
            /// <param name="unzippath">解压缩到指定目录</param>  
            /// <returns>解压后的文件列表</returns>  
            public List<string> UnZip(string zipfilepath, string unzippath)
            {
                //解压出来的文件列表  
                List<string> unzipFiles = new List<string>();
    
                //检查输出目录是否以“\\”结尾  
                if (unzippath.EndsWith("\\") == false || unzippath.EndsWith(":\\") == false)
                {
                    unzippath += "\\";
                }
    
                ZipInputStream s = new ZipInputStream(File.OpenRead(zipfilepath));
                ZipEntry theEntry;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    string directoryName = Path.GetDirectoryName(unzippath);
                    string fileName = Path.GetFileName(theEntry.Name);
    
                    //生成解压目录【用户解压到硬盘根目录时,不需要创建】  
                    if (!string.IsNullOrEmpty(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }
                    if (fileName != String.Empty)
                    {
                        //如果文件的压缩后大小为0那么说明这个文件是空的,因此不需要进行读出写入  
                        if (theEntry.CompressedSize == 0)
                            continue;
                        //解压文件到指定的目录  
                        directoryName = Path.GetDirectoryName(unzippath + theEntry.Name);
                        //建立下面的目录和子目录  
                        Directory.CreateDirectory(directoryName);
    
                        //记录导出的文件  
                        unzipFiles.Add(unzippath + theEntry.Name);
    
                        FileStream streamWriter = File.Create(unzippath + theEntry.Name);
    
                        int size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        streamWriter.Close();
                    }
                }
                s.Close();
                GC.Collect();
                return unzipFiles;
            }
  • 相关阅读:
    OGNL和Struts2标签
    Struts2中使用Servlet API步骤
    Struts2配置详解
    Strust的基础情况
    分页套用
    删除(注意,删除后,后面顶上去,所以id会一直变,所以我们用class来定义,因为id是唯一的)
    搭建SpringMVC+Mybatis框架并实现数据库的操作
    使用映射接口实现数据库的操作
    django 路由系统
    http协议
  • 原文地址:https://www.cnblogs.com/zwbsoft/p/16227444.html
Copyright © 2020-2023  润新知