title: Unity - Reading text files (Android & Web Player)
body: <p>I'm trying to read a text file in Unity. I have problems.</p>
  
  <ol>
  <li><p>In desktop, when I generate the Stand Alone, I need to copy manually the text file. I don't know how include inside my application.</p></li>
  <li><p>In web application (and Android), I copy the file manually but my game can't find it.</p></li>
  </ol>
  
  <p>This is my "Read" code:</p>
  
  <pre><code>public static string Read(string filename) {
  
          //string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, filename);
          string filePath = System.IO.Path.Combine(Application.dataPath, filename);
          string result = "";
  
          if (filePath.Contains("://")) {
  
              // The next line is because if I use path.combine I
              // get something like: "http://bla.bla/bla\filename.csv" 
              filePath = Application.dataPath +"/"+ System.Uri.EscapeUriString(filename);
              //filePath = System.IO.Path.Combine(Application.streamingAssetsPath, filename);
  
              WWW www = new WWW(filePath);
  
              int timeout = 20*1000;
  
              while(!www.isDone) {
                  System.Threading.Thread.Sleep(100);
                  timeout -= 100;
  
                  // NOTE: Always get a timeout exception ¬¬
                  if(timeout &lt;= 0) {
                      throw new TimeoutException("The operation was timed-out ("+filePath+")");
                  }
              }
  
              //yield return www;
              result = www.text;
          } else {
  
          #if !UNITY_WEBPLAYER
              result = System.IO.File.ReadAllText(filePath);
          #else
              using(var read = System.IO.File.OpenRead(filePath)) {
                  using(var sr = new StreamReader(read)) {
                      result = sr.ReadToEnd();
                  }
              }
          #endif
  
          }
  
          return result;
      }
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>How can I include my "text file" as a Game Resource?</p></li>
  <li><p>Is something wrong on my code? </p></li>
  </ol>