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 SocheaKhan · Jun 11, 2020 at 08:10 AM · android buildresources

How to read file on android built from Unity?

link text

This code is work on unity editor, but not android built. I would like to ask for help please !

dataparser.txt (5.9 kB)
Comment
Add comment · Show 2
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 ShadyProductions · Jun 11, 2020 at 08:23 AM 0
Share

We cannot access the file, can you pastebin or 0bin it please if it is large? Also it is most likely the location you are reading file from is wrong. You must use Application.persistentDataPath or if you use strea$$anonymous$$g assets then Application.Strea$$anonymous$$gAssetsPath

avatar image SocheaKhan ShadyProductions · Jun 11, 2020 at 08:33 AM 0
Share

Thanks for your reply. I have posted my code again. Please help me check ! BEST !

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rh_galaxy · Jun 11, 2020 at 01:32 PM

To use Resources.Load on a custom file you need to place the file in your project path on your PC "/Assets/Resources/test/textfile.txt", and skip the extension in the code like this:

 string szFilePath = "test/";
 string szFilenameNoExt = "textfile";
 TextAsset f = (TextAsset)Resources.Load(szFilePath + szFilenameNoExt);

This will work to read files that are static (exist at compile time).

Comment
Add comment · Show 7 · 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 SocheaKhan · Jun 11, 2020 at 02:02 PM 0
Share

Thanks so much for your help.

But How to call it to use ? I mean i can not use f.openText right?

avatar image ShadyProductions SocheaKhan · Jun 11, 2020 at 05:14 PM 0
Share

https://docs.unity3d.com/ScriptReference/TextAsset.html I google TextAsset this is what I find, literally the first thing Properties it says text: The text contents of the .txt file as a string. (Read Only)

so maybe try f.text and in the future maybe try use google and common sense

avatar image SocheaKhan ShadyProductions · Jun 11, 2020 at 05:21 PM 0
Share

No, because I can not change. The original is FileInfo located the file directory and TextReader will read the line. When you told me to change to Resources.Load, the TextReader is error and I dont know what to change for the fileinfo and textreader.

Show more comments
avatar image rh_galaxy · Jun 11, 2020 at 09:27 PM 0
Share

Don't use TextReader. Continue with this to parse the file text contents as a csv file (comma separated file)

 string szFileText = System.Text.Encoding.UTF8.GetString(f.bytes);
 string[] szLines = szFileText.Split((char)10);
 
 char[] szSeparator = { (char)',' };
 string[] szTokens = szLines[0].Trim('\r', '\n').Split(szSeparator, 
     StringSplitOptions.RemoveEmptyEntries);
 //szTokens[0] is first value in the file, do the parsing with a loop for each line and each
 //value. Use Split and Trim however needed to get the values from your text
avatar image SocheaKhan rh_galaxy · Jun 12, 2020 at 06:40 AM 0
Share

Thank you so much, I'll take a try first :)

avatar image SocheaKhan rh_galaxy · Jun 12, 2020 at 07:29 AM 0
Share

I have to change everything, and it's error. Could I have your contact please?

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

135 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 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 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 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 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 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 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

How to get Resources filepath on Android device? 2 Answers

Resourse.Load randomly fails on android device 0 Answers

CommandInvokationFailure: Failed to re-package resources. 0 Answers

Android build error. Failed to re-package resources. 3 Answers

Calling Instantiate from a function within a class 2 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