string resourcePath_ = Path.Combine(persistentDataPath_, "151515")
//设置存储位置
string zipPath_ = (resourcePath_ + ".zip").Replace(@"\", "/")
if (Directory.Exists(resourcePath_))
Directory.Delete(resourcePath_, true)
if (File.Exists(zipPath_))
File.Delete(zipPath_)
String filePath = @"您的url地址"//本地路径不行,必须是http或者https或者www才可以
//写入流
FileStream stream = File.Open(zipPath_, FileMode.OpenOrCreate)
//创建httpwebrequest请求
HttpWebRequest downloadRequest = (HttpWebRequest)WebRequest.Create(filePath)
downloadRequest.Method = "GET"
using (HttpTools downloader_ = new HttpTools(downloadRequest, null, stream))
{
yield return downloader_
bool updateResult = false
//清空数据流关闭
stream.Flush()
stream.Close()
bool decompressFinish_ = false
if (downloader_.Exception == null)
{
// 解压资源包
AsyncExtra(zipPath_, persistentDataPath_, delegate(bool b)
{
updateResult = b
decompressFinish_ = true
})
// 等待压缩完成
while (!decompressFinish_) yield return null
}
else
{
//ReportManager.Inst.ReportException(this.downloader_.Exception)
decompressFinish_ = true
}
if (updateResult)
{
LoadPrint("更新完成")
}
else
{
LoadPrint("更新失败")
}
}
//第二部分
/// <summary>
/// 将指定的zip文件解压缩到指定目录
/// </summary>
/// <param name="path_"></param>
/// <param name="targetDir"></param>
void AsyncExtra(string path_, string targetDir, Action<bool>cb)
{
Thread t = new Thread(delegate()
{
try
{
if (!Directory.Exists(targetDir) &&!string.IsNullOrEmpty(targetDir))
Directory.CreateDirectory(targetDir)
using (ZipInputStream zipStream = new ZipInputStream(File.OpenRead(path_)))
{
//this.state_ = ResourceUpdateState.Decompression
ZipEntry entry
while ((entry = zipStream.GetNextEntry()) != null)
ExtraZipEntry(zipStream, entry, targetDir)
}
cb(true)
}
catch (Exception e)
{
//ReportManager.Inst.ReportException(e)
cb(false)
}
})
t.Start()
}
//第三部分
void ExtraZipEntry(ZipInputStream zipStream, ZipEntry entry, string outputDir)
{
int bufferSize_ = 8192
byte[] buffer = new byte[bufferSize_]
int readSize_ = 0
string directroyName = Path.GetDirectoryName(entry.Name)
string fileName = Path.GetFileName(entry.Name)
string absDirectory = Path.Combine(outputDir, directroyName)
string absFile = Path.Combine(absDirectory, fileName)
Debug.Log("解压信息:" + directroyName + " " + fileName + " " + absDirectory + " " + absFile)
if (!string.IsNullOrEmpty(directroyName))
Directory.CreateDirectory(absDirectory)
int size = (int)entry.Size
using (FileStream fileStream = File.Create(absFile))
{
while (readSize_ <size)
{
int rd = zipStream.Read(buffer, 0, Math.Min(size - readSize_, bufferSize_))
fileStream.Write(buffer, 0, rd)
readSize_ += rd
}
}
}
首先 得购买空间:服务商会给你一个FTP地址和用户名 密码其次:找一个FTP软件 flashfxp 输入服务商提供的FTP地址 用户名 密码登陆 上传
或直接打开浏览器 输入FTP地址 输入用户名 密码 把做好的网页 复制 粘贴上去主OK了
请检查是否使用了同一个SessionId也就是说当下载同一个文件时 可能会对应一个特定的SessionId
第一次请求时可能SessionId有效 但是第二次请求时可能已经失效 所以下载不到数据
还有你题目描述不是很清楚
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)