咋从服务器下载多个txt文档啊,用www
M丶随心忄 2018-11-09 05:01:39 /// <summary>
/// 从服务器上下载txt文本(到指定位置)
/// </summary>
/// <param name="Url">服务器地址</param>
/// <param name="filePath">要下载到的文件路径</param>
/// <returns></returns>
private IEnumerator DownLuDianJs(string Url,string FilePath)
{
WWW wW = new WWW(Url);
yield return wW;
while (wW.isDone)//在这能直接下载下来txt文档到指定的目录下吗!还有它能把文档分开吗还是说全在一起
{
Debug.Log("下载完成");
StreamWriter sw = new StreamWriter(FilePath);
sw.Write(wW.text.ToString());
sw.Close();
sw.Dispose();
}
}
/// <summary>
/// 需要的是服务器下载地址和本地路径
/// </summary>
public void DownTxt()
{
StartCoroutine(DownLuDianJs("服务器地址", Application.dataPath + "/Resources/Waypoints/"));
}
上面是我写的代码,感觉不对,我的疑问是如何用WWW从服务器下载很多txt文档,到指定位置;
(比如:服务器里有3个txt文档,名字分别是A,B,C===;我下载下来是将其放在我指定的目录下,并且也是A,B,C这样的分开的txt文本)
自己起文件名很好写,但想要的是 不需要手动起名字,只需要 把txt文件下载到指定目录。