zoukankan      html  css  js  c++  java
  • 解析压缩文件zip

       public static string UnZipFile(string TargetFile, string EndFile)
            {
                try
                {
                    using (FileStream fs = File.Create(EndFile))
                    {
                        //读取压缩文件(zip文件),准备解压缩
                        ZipInputStream inputstream = new ZipInputStream(File.OpenRead(TargetFile.Trim()));
                        ZipEntry entry;
    
                        //根目录下的第一个子文件夹的名称
                        while ((entry = inputstream.GetNextEntry()) != null)
                        {
                            //得到根目录下的第一级子文件夹下的子文件夹名称
                            string fileName = Path.GetFileName(entry.Name);
                            if (fileName != String.Empty)
                            {
                                int size = 2048;
                                byte[] data = new byte[2048];
                                while (true)
                                {
                                    size = inputstream.Read(data, 0, data.Length);
                                    if (size > 0)
                                    {
                                        fs.Write(data, 0, size);
    
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                fs.Close();
    
                            }
                        }
                        inputstream.Close();
                    }
                }
                catch (Exception ex)
                {
                    return "NG";
                }
                return "OK";
            }
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/my2020/p/14345299.html
Copyright © 2011-2022 走看看