项目的配置文件为了和服务器保持一致,每次打包时都从网上下载配置文件,由于下载的是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学习笔记之static

    1.static可以用于修饰成员变量.方法以及块,并不会改变类中成员的权限修饰,如:private修饰的成员变量,类外只能类名或非私有方法调用,而不能使用对象名调用. 2.static方法和成员变量, ...

  2. gvim work notes.. a few days' work on 64bit vim and plugin compilations

    (a 600MB+ sized c/c++ compiler which is capable of hi-light and JB styled completion!! and of-course ...

  3. php 大转盘抽奖

    包在文件中 lottery.zip <!DOCTYPE HTML><html><head><meta charset="utf-8"> ...

  4. 用for、while、do-while循环输出10句“好好学习,天天向上!”

    #include "stdio.h" void main() { int time; ;time<=;time++) printf("%d.好好学习,天天向上!\n ...

  5. Theos tweak MSHookFunction

    #import "substrate.h" static FILE * (*s_orig_fopen) ( const char * filename, const char * ...

  6. sphinx分域搜索【不】需要在conf文件中使用sql_field_string

    请看sql_field_string的文档说明: # combined field plus attribute declaration (from a single column) # stores ...

  7. 禁止root远程登录

    Linux禁止root远程登录 ssh的修改vi /etc/ssh/sshd_config将默认的#PermitRootLogin yes去注释改为PermitRootLogin no service ...

  8. 剑指offer 复杂链表的复制 (有向图的复制)

    时间复杂度O(3N) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...

  9. 关于oracle数据库的监听器配置问题

    一般我都会把ORACLE安装到E盘,监听器会自动安装到D盘,文件名叫 instantclient_12_1 监听器文件listener.ora的设置和tnsnames.ora设置 :http://bl ...

  10. javascript的事件冒泡,阻止事件冒泡和事件委托, 事件委托是事件冒泡的一个应用。

    首先,弄明白js 当中,什么是事件,事件模型在js中是如何设计的.什么是事件冒泡? 什么是“事件冒泡”呢?假设这里有一杯水,水被用某种神奇的方式分成不同颜色的几层.这时,从最底层冒出了一个气泡,气泡会 ...