项目的配置文件为了和服务器保持一致,每次打包时都从网上下载配置文件,由于下载的是zip压缩包,还需要解压,代码如下:

using ICSharpCode.SharpZipLib.Zip;
using System;
using System.IO;
using System.Net; public class CsvFilesDownloader
{
const string RootUrl = "http://xxx-"; // csv 文件下载地址
const string CSVDirAssetPath = "Assets/CSVConvertScripts/CSVFiles"; // csv 文件保存目录 #region Version public enum Version
{
Trunk, CBT3, CBT2, CBT1, TT, Daye, M4, M3, M2,
} #endregion public static void Start(Version version)
{
string url = RootUrl + version;
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Post; var response = request.GetResponse();
var stream = response.GetResponseStream();
string saveDirPath = AssetBundleItem.GetFullPath(CSVDirAssetPath); Decompress(stream, saveDirPath);
} // 需使用开源类库:ICSharpCode.SharpZipLib,可以网上下载
static void Decompress(Stream src, string targetDirPath)
{
if (src == null)
throw new ArgumentNullException("src");
if (string.IsNullOrEmpty(targetDirPath))
throw new ArgumentException("targetDirPath"); if (!Directory.Exists(targetDirPath))
Directory.CreateDirectory(targetDirPath); using (ZipInputStream decompressor = new ZipInputStream(src))
{
ZipEntry entry; while ((entry = decompressor.GetNextEntry()) != null)
{
if (entry.IsDirectory)
continue; if (Path.GetExtension(entry.Name).ToLower() != ".csv")
continue; string fileName = Path.GetFileName(entry.Name);
string path = Path.Combine(targetDirPath, fileName);
byte[] data = new byte[2048]; using (FileStream streamWriter = File.Create(path))
{
int bytesRead;
while ((bytesRead = decompressor.Read(data, 0, data.Length)) > 0)
streamWriter.Write(data, 0, bytesRead);
}
}
}
} }

  

转载请注明出处:http://www.cnblogs.com/jietian331/p/5019492.html

c#之从服务器下载压缩包,并解压的更多相关文章

  1. php下载文件,解压文件,读取并写入新文件

    以下代码都是本人在工作中遇到的问题,并完成的具体代码和注释,不多说,直接上代码: <?php      //组织链接      $dataurl = "http://118.194.2 ...

  2. 第1节 IMPALA:4、5、linux磁盘的挂载和上传压缩包并解压

    第二步:开机之后进行磁盘挂载 分区,格式化,挂载新磁盘 磁盘挂载 df -lh fdisk -l 开始分区 fdisk /dev/sdb   这个命令执行后依次输 n  p  1  回车  回车  w ...

  3. mac通过自带的ssh连接Linux服务器并上传解压文件

    需求: 1:mac连接linux服务器 2:将mac上的文件上传到linux服务器指定位置 3:解压文件 mac上使用命令,推荐使用 iterm2 .当然,也可以使用mac自带的终端工具. 操作过程: ...

  4. Hadoop:读取hdfs上zip压缩包并解压到hdfs的实现代码

    背景: 目前工作中遇到一大批的数据,如果不压缩直接上传到ftp上就会遇到ftp空间资源不足问题,没办法只能压缩后上传,上穿完成后在linux上下载.但是linux客户端的资源只有20G左右一个压缩包解 ...

  5. 【DataBase】 在Windows系统环境 下载和安装 解压版MySQL数据库

    MySQL官网解压版下载地址:https://dev.mysql.com/downloads/mysql/ 为什么不推荐使用安装版?无脑下一步,很多配置的东西学习不到了 点选第一个就好了,下面的是调试 ...

  6. ubuntu下各种压缩包的解压命令

    .tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...

  7. FTP下载导致Zip解压失败的原因

    情形:网关通过FTP下载快钱对账文件时通过Apache下commons-net的commons-net-3.5.jar进行封装,对账文件中有中文和英文的文字,大部分情况下能够下载成功,而且也能解压成功 ...

  8. linux下压缩包的解压

    linux下 最常见的是 .tar.gz 包和.tar.bz2包 .tar.gz格式的压缩包解压命令是:          tar   -zxvf   xx.tar.gz .tar.bz2格式的压缩包 ...

  9. 如何下载安装MySQL 解压版和安装版以及2个版本的区别

    参考链接:https://blog.csdn.net/qq_33800083/article/details/80722829

随机推荐

  1. java regex possissive relunctant

    Java正则表达中Greedy Reluctant Possessive 的区别 分类: java 2015-01-16 00:28 1588人阅读 评论(9) 收藏 举报 正则表达式Java 目录( ...

  2. UIImageView 的contentMode属性应用

    UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中.居右,是否缩放等,有以下几个常量可供设定:UIViewContentModeScaleToFillUIView ...

  3. 贪心<haonan>

    题意: 有一列数,每次在相邻的两个书里面选择一个大数留下,同时ans+大数.问题是,求ans的最小值. 题解: 如果a[i]>a[i-1],那么ans+=a[i]; 如果a[i]>=a[i ...

  4. HDU 3594 Cactus (强连通分量 + 一个边只能在一个环里)

    题意:判断题目中给出的图是否符合两个条件.1 这图只有一个强连通分量 2 一条边只能出现在一个环里. 思路:条件1的满足只需要tarjan算法正常求强连通分量即可,关键是第二个条件,我们把对边的判断转 ...

  5. Ubuntu安装Anaconda3

    下载  https://www.continuum.io/downloads#_unix Python3.5 Linux 32-bit 安装 bash Anaconda3-2.4.0-Linux-x8 ...

  6. CodeForces 546 D. Soldier and Number Game(素数有关)

    Description Two soldiers are playing a game. At the beginning first of them chooses a positive integ ...

  7. PAT (Advanced Level) 1111. Online Map (30)

    预处理出最短路再进行暴力dfs求答案会比较好.直接dfs效率太低. #include<cstdio> #include<cstring> #include<cmath&g ...

  8. 二分图最大匹配 Hopcroft-Karp算法模板

    #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> ...

  9. 2333: [SCOI2011]棘手的操作[写不出来]

    2333: [SCOI2011]棘手的操作 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1979  Solved: 772[Submit][Stat ...

  10. 善用log日志

    #-*- coding:utf-8 -*- import logging logger = logging.getLogger() #定义一个log日志对象 hdlr = logging.FileHa ...