c#之从服务器下载压缩包,并解压
项目的配置文件为了和服务器保持一致,每次打包时都从网上下载配置文件,由于下载的是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#之从服务器下载压缩包,并解压的更多相关文章
- php下载文件,解压文件,读取并写入新文件
以下代码都是本人在工作中遇到的问题,并完成的具体代码和注释,不多说,直接上代码: <?php //组织链接 $dataurl = "http://118.194.2 ...
- 第1节 IMPALA:4、5、linux磁盘的挂载和上传压缩包并解压
第二步:开机之后进行磁盘挂载 分区,格式化,挂载新磁盘 磁盘挂载 df -lh fdisk -l 开始分区 fdisk /dev/sdb 这个命令执行后依次输 n p 1 回车 回车 w ...
- mac通过自带的ssh连接Linux服务器并上传解压文件
需求: 1:mac连接linux服务器 2:将mac上的文件上传到linux服务器指定位置 3:解压文件 mac上使用命令,推荐使用 iterm2 .当然,也可以使用mac自带的终端工具. 操作过程: ...
- Hadoop:读取hdfs上zip压缩包并解压到hdfs的实现代码
背景: 目前工作中遇到一大批的数据,如果不压缩直接上传到ftp上就会遇到ftp空间资源不足问题,没办法只能压缩后上传,上穿完成后在linux上下载.但是linux客户端的资源只有20G左右一个压缩包解 ...
- 【DataBase】 在Windows系统环境 下载和安装 解压版MySQL数据库
MySQL官网解压版下载地址:https://dev.mysql.com/downloads/mysql/ 为什么不推荐使用安装版?无脑下一步,很多配置的东西学习不到了 点选第一个就好了,下面的是调试 ...
- ubuntu下各种压缩包的解压命令
.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...
- FTP下载导致Zip解压失败的原因
情形:网关通过FTP下载快钱对账文件时通过Apache下commons-net的commons-net-3.5.jar进行封装,对账文件中有中文和英文的文字,大部分情况下能够下载成功,而且也能解压成功 ...
- linux下压缩包的解压
linux下 最常见的是 .tar.gz 包和.tar.bz2包 .tar.gz格式的压缩包解压命令是: tar -zxvf xx.tar.gz .tar.bz2格式的压缩包 ...
- 如何下载安装MySQL 解压版和安装版以及2个版本的区别
参考链接:https://blog.csdn.net/qq_33800083/article/details/80722829
随机推荐
- keepalived 健康检测
1.TCP方式 详见:http://www.cnblogs.com/tengpan-cn/p/5776574.html 以下内容,都是基于此进行修改 2.HTTP_GET 根据返回状态判断服务器是否正 ...
- rollout
#! /bin/ksh # 设置环境变量 ############### ### UAT ### ############### export ENVS=/test/change/env/e ...
- IDL和生成代码分析
IDL:接口描述语言 这里使用thrift-0.8.0-xsb这个版本来介绍IDL的定义以及简单实例分析. 1. namespace 定义包名 2.struct 结构体,定义服务接口的参数和返回值用到 ...
- pkgmgmt: Comparison between different Linux Systems..
found this page.. already done by precedents.. installation: aptitude install apt-get install yum in ...
- WebKit框架 浅析
摘要 WebKit是iOS8之后引入的专门负责处理网页视图的框架,其比UIWebView更加强大,性能也更优. iOS中WebKit框架应用与解析 一.引言 在iOS8之前,在应用中嵌入网页通常需要使 ...
- iOS8中的动态文本
原文链接 : Swift Programming 101: Mastering Dynamic Type in iOS 8 原文作者 : Kevin McNeish Apple声称鼓励第三方App能够 ...
- 4--OC --合成存取器方法
1. 从OC 2.0开始就已经可以自动生成设置函数方法和获取函数方法(统称为存取器方法). 什么是 @property 和 @synthesize ? @property 和 @synthesize ...
- Light OJ 1008
找规律. 首先令n=sqrt(s),上取整.讨论当n为偶数时,若n*n-s<n则x=n,y=n*n-s+1否则x=-n*n+2*n+s-1,y=n;如果n为奇数,交换x,y即可,对称的. Sam ...
- linux 用户管理维护 清缓存
#echo 1 > /proc/sys/ vm/drop_caches 2013.10.10 其实一直user group一直都没去弄清楚 只是没去归类,@@一种是对用户/组直接修改(同时也更改 ...
- PAT1027
People in Mars represent the colors in their computers in a similar way as the Earth people. 火星人在他们的 ...