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 kubas1242 · Nov 08, 2013 at 06:29 PM · androidtexturestream

Streamreader read .txt file with Android

I need to read some lines from .txt file and after ceratain string("co_wypisac") return the remaining part of the line as a string. It works perfectly while running on unity, but after building and exporting to android device the data from file is not visible (no display box). I do not want to use XML for few reasons. Anyone got an idea?

stream filetoread="file.txt";

StreamReader odczytaj = new StreamReader(Application.dataPath + "/Language_files/" + filetoread);

     string odczyt;
     while((odczyt = odczytaj.ReadLine())!= null)     
     {
     if(odczyt.Contains(co_wypisac))                    
         {
             odczyt = odczyt.Substring(odczyt.IndexOf(' ') + 1);          
             odczyt= odczyt.Replace("\\n",System.Environment.NewLine)
             odczytaj.Close();
             return odczyt;       
         }
     }
     odczytaj.Close();
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 gmonks · Feb 20, 2014 at 09:58 AM 0
Share

Great! thanks

1 Reply

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

Answer by flamy · Nov 08, 2013 at 07:20 PM

The reason is simple the target file is not included in the build since the file didn't have any linked reference with the scene. So wat you have to do is make unity force include the file.

note that files inside Resources folder is always included in build.

so all u have to do is make a folder called Resources under assets folder and move the language folder into it.

so now you hav to,pass path as Application.datapath+"Resources/Language_files/"+filetoread

Edit sorry for the blunder I have made,

2 points to be mentioned, In android, the file you have kept in any of the project folder cannot be accessed seperately. Because of this, You wont be able to use streamreader. Files in resource folder can be accessed and loaded at runtime. but not using stream reader. you have to load it as a text asset and get the whole content of file loaded.

one thing to note is that the file should be of .txt extension for loading it using TextAsset.

//the file name is testfile.txt so im using here as testfile

 TextAsset odczytaj = Resources.Load("Language_files/testfile") as TextAsset; 
             
    
            string[] linesFromfile = odczytaj.text.Split("\n"[0]);
         foreach (string odczyt in linesFromfile)
         {
             Debug.Log(odczyt);
             if(odczyt.Contains(co_wypisac))              
                {
                 //dosomething
             }
         }

The code of yours would change a bit and resemble like this.

Comment
Add comment · Show 5 · 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 flamy · Nov 09, 2013 at 09:23 AM 0
Share

sorry for the mistake, check the answer now i have edited it

avatar image kubas1242 · Nov 09, 2013 at 04:23 PM 0
Share

GREAT IT WOR$$anonymous$$ED!! THAN$$anonymous$$S $$anonymous$$AN!

avatar image flamy · Nov 09, 2013 at 05:53 PM 0
Share

mark the answer as accepted, if the problem is solved :) :)

avatar image Issah · Feb 03, 2015 at 10:06 AM 0
Share

I use this for JSON, strea$$anonymous$$g doesn't work but your solution works ! thank you i upvote you

avatar image Fragmental · Sep 18, 2018 at 06:57 PM 0
Share

The Strea$$anonymous$$gAssets folder is also included in the build, but the files are not loaded into Unity. It is a good option to use with StreamReader, but it does not work with Resources.Load

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Alpha problem with textures on a plane 2 Answers

Unity 2018 UGUI Android Sprite Textures Not Rendering Correctly 1 Answer

Android textures not loading 1 Answer

DXT texture format on Mali GPU 0 Answers

Toggle button GUI texture not changing on click? 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