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
0
Question by billythegoat · Nov 13, 2014 at 09:23 PM · c#androidtext

How to access a text file once it's on Android Device so I can read it.

I've thoroughly read through every related question and tried everything, so I'm sure it's just me not doing it right.

I can't seem to find out the write combination of filepaths to access the text file after everything is compressed into APK.

Do I need to use Appication.persistentDataPath at all? I have no idea. I've tried everything.

 if (Application.platform == RuntimePlatform.Android)
         {
             filePath = System.IO.Path.Combine(Application.streamingAssetsPath, fileName);
             LoadWWW (filePath);
         }
 private void LoadWWW(string fileName)
     {
         try
         {
             string line;
             WWW www = new WWW(filePath);
             StringReader reader = new StringReader(www.text, Encoding.Default);
             using (reader)
             {
                 do
                 {
                     line = reader.ReadLine ();
                     
                     if(line != null)
                         ;//do something
                 }
                 while(line != null);
                 
                 reader.Close();
             }
         }
         catch (Exception e)
         { 
             Debug.Log(e.Message);
         }
     }

I'm sure I'm doing something super obviously wrong, I'm really new to c# and unity and everything. Any help would be great.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jeff-Kesselman · Nov 13, 2014 at 09:24 PM

in line 17 you do a read line

in line 24 you do another read line into the same variable, over-writing the first line you read

reverse the order of lines 24 and 25 (or everything that "Do Something" in line 25 represents)

"Do Something" first, THEN read the next line.

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 billythegoat · Nov 13, 2014 at 10:05 PM 0
Share

OH sorry I shouldn't have included that. But that is intentional. I erased most of the code that makes that part make sense. What it's doing is it searches the text for a line then that line tells the for loop how many iterations to go through and then "do something" is for those specific lines only. I edited that part out to prevent any confusion

In the editor it works perfectly, it reads the file and everything. It's a pathing issue and Android needing to use WWW that is causing the device either not to be able to read the file or StreamReader not working with a www.text, or something else I'm doing wrong, I don't know for sure.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

changing text using .text works in editor but not on android device 0 Answers

[Android] Open .txt file from c# 1 Answer

Adjusting UI to cellphone screen size 0 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