Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DarmMan · Aug 07, 2015 at 12:06 PM · androidandroid buildtxt

how put txt file into android package

I have programme that have to read txt file, on coputer it work but on android don't, I don't know how to locate my txt file's that they I coud read the with path. I was tried to locate txt file in Resources file, first I have using System.IO; and path:

 string path_first_level= @"Resources/first_level.txt";

the I use ReadAllLines:

 first_level = System.IO.File.ReadAllLines(path_first_level);

ReadAllLines is best for me becaus it return a table when every line is an object in table so I navigate in txt with this, on computer it works, what should I change with path to use it on android

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
Best Answer

Answer by troien · Aug 07, 2015 at 12:25 PM

Since you did place your text files in the resources folder, I assume you did read something about this.

However, the way you try to access these files is not the Unity way. In fact, this probably won't work if you would make a build for windows/mac either (unless you manually place the files at the given path after you build). Only in the editor this should work.

By reading the Description of the Resources page you can see how you should acces your data inside the Resources folder.

In your case, sinse you are trying to read a text file. Loading a TextAsset is probably what you want to do. Note that the path parameter is not the full path. In your case "first_level.txt" will probably do the trick (not sure if the .txt is needed, but I'm sure you'll be able to figure that out :p)

 TextAsset asset = Resources.Load<TextAsset>("YourPathHere");
 Debug.Log(asset.text);

As for why you ca't access your files using System.IO. This is because your files don't exist. Or at least, not in the same way as they do inside your project. For more information on this, this wiki article covers this. (the "Resources" part)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to post process Unity-built dll before il2cpp kicks in? 1 Answer

Android App crashing while downloading data from firebase 0 Answers

I am having trouble building the project for android (i can't build) 0 Answers

Export android with compute shader doesn't work on unity 2018 1 Answer

Unity Android Build Dosn't Work On The Device But Works In The Editor. 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