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
1
Question by Rikimaru · Aug 16, 2013 at 11:39 AM · androidfile-io

Load text file on Streaming assets in Android

On unity documents, Streaming assets are pressed to jar file.

I played my game on android, My text file on streaming assets did not be loaded.

 string path = Application.streamingAssetsPath + "/" + filename;
         if(Application.platform == RuntimePlatform.Android)
         {
             path =  "jar:file://" + Application.dataPath + "!/assets/" + filename;
         }
 
         if (File.Exists(path))
         {
             FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read);
             StreamReader sr = new StreamReader( file );
             
             string str = null;
             str = sr.ReadLine ();
             
             sr.Close();
             file.Close();
             
             return str;
         }
         
         else
         {
             return null;
         }

this is my code of read file.

I need your help T.T

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

4 Replies

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

Answer by pitimoi · Aug 16, 2013 at 01:20 PM

Hi,

I think the path Application.streamingAssetsPath + "/" + filename; is still valid on android, you don't need to use something else to access your data on android.

Anyway, try to read your file using a WWW instead of using a filestream, it should works better with unity.

Comment
Add comment · Show 3 · 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 Rikimaru · Aug 16, 2013 at 02:15 PM 0
Share

Thanks for answer. I want to ask if I use www,how can I code that. www data = new www( "jar:file://" + Application.dataPath + "!/assets/" +filename); like this???

avatar image pitimoi · Aug 19, 2013 at 04:34 PM 0
Share

$$anonymous$$mmh, I don't have any project to test right now, but what I would try is :

 WWW data = new WWW(Application.strea$$anonymous$$gAssetsPath+"/"+filename);
 yield return data;
 
 if(string.IsNullOrEmpty(data.error))
 {
    myText = data.text;
 }

You should place it into a Coroutine to use WWW with Unity.

avatar image sanmn19 · Jan 13, 2014 at 06:53 PM 0
Share

Thank you for this invaluable answer.

avatar image
2

Answer by ereneld · Feb 22, 2017 at 08:31 AM

it is always better to use with path.combine

 string filename = "";
 Path.Combine(Application.streamingAssetsPath, filename);
 
 
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
avatar image
0

Answer by Gunhi · Jun 29, 2017 at 04:20 AM

Here you go: https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html

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 Liderangel · Jun 05, 2019 at 02:21 AM 0
Share

"It is not possible to access the Strea$$anonymous$$gAssets folder on WebGL and Android platforms"

avatar image
0

Answer by uzairamirs · Apr 12, 2018 at 12:16 PM

@sanmn19 bro/sir, can you please help me? I am stuck in this.. I am trying to access streaming assets in an apk and failing for 3 days.. If you could help it would be very kind of you.

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

22 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

Related Questions

android browse and read text files 1 Answer

High score local [Android] 1 Answer

Opening data file from asset folder 2 Answers

Reading from a file not working on Android 0 Answers

How to set persistent data path to sdcard on android 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