zoukankan      html  css  js  c++  java
  • .net5 提取压缩包内指定文件内容无需解压

    using System.IO;
    using System;
    using System.IO.Compression;

    /// <summary>
    /// 提取压缩包内指定文本内容,无需解压
    /// </summary>
    /// <param name="fileName">压缩文件路径</param>

    /// <param name="modelDefectFileName">txt文件名</param>
    /// <returns></returns>
    public static string GetZipTxt(string fileName,string txtFileName)
    {
    //var fileName = @$"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\123.zip";
    string content = string.Empty;
    using (FileStream zipToOpen = new FileStream(fileName, FileMode.Open))
    {
    using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
    {
    ZipArchiveEntry readmeEntry = archive.GetEntry(txtFileName);
    using (var reader = new StreamReader(readmeEntry.Open()))
    {
    content = reader.ReadLine();
    Console.WriteLine(content);
    }
    }
    }
    return content;
    }

     ================================

    参考网址:

    https://docs.microsoft.com/zh-cn/dotnet/standard/io/how-to-compress-and-extract-files

    ==========================

  • 相关阅读:
    libevent(十)bufferevent 2
    libevent(九)bufferevent
    maven本地库更新失败
    IDEA常用快捷键
    ELASTIC SEARCH 安装
    Hbase建模选择
    ElasticSearch关键概念
    Nginx+tomcat 负载均衡
    MapReduce (MRV1)设计理念与基本架构
    Kafka安装验证及其注意
  • 原文地址:https://www.cnblogs.com/longhao510/p/15670858.html
Copyright © 2011-2022 走看看