• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by alienweb · Jul 20, 2014 at 12:31 PM · textloadfileweb

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image creatingvfx · Sep 05, 2018 at 11:05 AM 0
Share

HEy brother I am creating app for Android too I dont know coding much, searched everywhere but found only that TO make text change dynamicaly from outside we have to create server and link the text to that sever but that topic goes completly off to me I think you are trying to that same ,if you can help then please reply how to make text change I want to change the text of my mobile app somehow everyweek without rebuilding

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ajketan · Jul 22, 2014 at 06:54 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ajketan · Jul 22, 2014 at 06:57 PM 0
Share

I use Application.persistent data path because it is convenient and consistent throughout all the platforms... you can use your resource directories as well but I have not tested working with them...

avatar image alienweb · Jul 23, 2014 at 08:18 AM 0
Share

thank you, it's exacly what i need !

avatar image
1

Answer by WilliamLeu · Jul 22, 2014 at 06:39 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Where to put my text files when exporting a project 2 Answers

Trouble creating a text file 4 Answers

How do I load a 60mb text file? 0 Answers

Read dialog text from text file in javascript 0 Answers

Executing code from a text file and writing changes to it 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges