Load and save text from web server

Hi all,

I’m doing an app for mobile, and i need to load text from web to use it after i unity.

So i would like to load the text and save it in a text asset (or .txt file).

There is my script :

using UnityEngine;
using System.Collections;

public class http : MonoBehaviour {
    public string url = "http://www.mywebsite.com/largetextfile.txt";
	public float progress = 0;
	private string text;

	IEnumerator demarre() {
        WWW www = new WWW(url);
        yield return www;
        text = www.text;
	progress = www.progress;

        // how to save it in a file ?

	}
	

}

When i debug (Debug.Log(www.text);)i have an error :

count <= std::numeric_limits::max()
UnityEditor.DockArea:OnGUI()
maxVertices < 65536 && maxIndices < 65536*3

get the length of the text and see if it’s over 16K characters. You might have a good string, but the editor might have problems displaying it to the debug log because it’s too large.

As for saving it, easiest way is WriteAllText.

Make sure that the “www.progress” part is completed 100% first… and then you can call the following function.
Stream reader and writer uses “System.IO” so you will have to make the header entry.

void WriteIntoMyLocalFile(string textFromServerFile)
    {
	string filePath;
        
	filePath = Application.persistentDataPath + "/LocalLargeTextFile.txt";
        
        using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
        {
            using (StreamWriter writer = new StreamWriter(fs))
            {                
                writer.Write(textFromServerFile);
                writer.Close();
                writer.Dispose();
	        }
            fs.Close();
            fs.Dispose();
	}        
    }

Use this function… This part of code is tested on iOS, Android and WP8.
It was a bit tricky to read the content from web for me…but I see that you have already figured that out.

Cheers

Ketan