Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by MythStrott · Sep 11, 2010 at 09:26 PM · textwwwinternetclouddata

How to read text file (.txt) from URL?

I need is to load a text file from my web server.

Comment
Add comment
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

3 Replies

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

Answer by Fattie · Jan 25, 2016 at 09:29 PM

 /* WebTextFileChecker.cs
 This checks the text in a text file on the web - believe it!
 */
 
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class WebTextFileChecker:MonoBehaviour
     {
     public void Start()
         {
         StartCoroutine(Check());
         }
     
     private IEnumerator Check()
         {
         WWW w = new WWW("http://yourserver.com/handyFile.txt");
         yield return w;
         if (w.error != null)
             {
             Debug.Log("Error .. " +w.error);
             // for example, often 'Error .. 404 Not Found'
             }
          else
              {
              Debug.Log("Found ... ==>" +w.text +"<==");
              // don't forget to look in the 'bottom section'
              // of Unity console to see the full text of
              // multiline console messages.
              }
          
         /* example code to separate all that text in to lines:
         longStringFromFile = w.text
         List<string> lines = new List<string>(
             longStringFromFile
             .Split(new string[] { "\r","\n" },
             StringSplitOptions.RemoveEmptyEntries) );
         // remove comment lines...
         lines = lines
             .Where(line => !(line.StartsWith("//")
                             || line.StartsWith("#")))
             .ToList();
         */
         
         }
     }

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
avatar image
0

Answer by ina · Dec 25, 2010 at 05:00 PM

1) Use myWWW = WWW(url); to fetch data from your server.

2) Parse the resulting string for the data segments you need. myWWW.text

You will probably need a couple of helper functions.

wwwStr2Array() converts a string you might get from your WWW fetch to an array. http://answers.unity3d.com/questions/33243/array-dump-to-string-for-send-via-www/33351#33351

You can use the same idea if your WWW returns a string like: username=fred&password=flintstones - you would just put it through the delimiter split in the above link again.

Once your values are in arrays, you can just manipulate them as you would usually.

Comment
Add comment · Show 1 · 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 Jawad Amjad · Feb 26, 2016 at 11:24 AM 0
Share

This Does not work on iPADs. Do you have any other option?

avatar image
0

Answer by Jlu · Mar 21, 2014 at 09:05 AM

You could also use uQuery:

 uQuery.Get("http://url.to/file.txt", function(data, xhr) {
     Debug.Log(data); // Prints the text
 });

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.

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

Transfer closed with bytes remaining to read 1 Answer

load file with www on webplayer 1 Answer

Why does accessing www.text blocks the coroutine using WWW class? 1 Answer

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

Internet reachability on iOS 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges