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
2
Question by moghes · May 09, 2015 at 05:28 PM · androiddatafilestreamexcel.exe

Reading from .CSV works fine on windows editor, and no data on device (Android)

Hello,

I have several excel files which I've exported to .csv and reading the data with FileStream and saving to custom classes .. everything working perfeclty when I run on the editor.

 string fileName = "/MyData/" + packages[i] + ".csv";
 streamReader = new StreamReader(File.OpenRead(Application.dataPath + fileName ));

since I have several .csv files I have the names in a List of strings. (naming and spelling are correct since data is displayed accurately on the editor).

I did an android build, and a blank screen, data is not retrieved . However a crash might result the same, but I have no errors/null values when runing on the editor.

So .. Is it related to the path ? Application.dataPath problems on devices?

or something related to the file format?

or if anyone has a different suggestion.

Thanks for your time :)

Comment
Add comment · Show 3
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 moghes · May 13, 2015 at 08:48 AM 0
Share

For more updates about my search.

it was mentioned,

 #if UNITY_ANDROID
         path = "file:///"+ Application.persistentDataPath;

in this post: http://answers.unity3d.com/questions/854658/android-persistent-data-loading-fails.html

but still data didnt appear

avatar image moghes · May 13, 2015 at 08:49 AM 0
Share

Also I tried strea$$anonymous$$g assets ins$$anonymous$$d of dataPath again data didn't load

avatar image moghes · May 13, 2015 at 08:51 AM 0
Share

I tried .txt ins$$anonymous$$d of .csv .... still the same , data was not loaded .. so its not the path, its not the format ..

I$$anonymous$$O its something related to a permission on Adroid ..

2 Replies

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

Answer by Kiichi · May 13, 2015 at 12:20 PM

If you need to include this file to the build you have the only one way: place it to the Resources folder and use Resources.Load. You can use *.bytes extension for binary data. For ex.:

 using (BinaryReader reader = new BinaryReader(new MemoryStream((Resources.Load(filename) as TextAsset).bytes)))
 {
     // Read your data here
 }

Comment
Add comment · Show 4 · 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 moghes · May 13, 2015 at 01:09 PM 0
Share

Thanks for the answer :) will try this method as well

avatar image moghes · May 13, 2015 at 01:23 PM 0
Share

@$$anonymous$$iichi your post helped me alot !! and many thanks however I am using a StreamReader and the actual file load is:

 StreamReader streamReader = new StreamReader(new $$anonymous$$emoryStream((Resources.Load("Test") as TextAsset).bytes));

But using $$anonymous$$emoryStream with Resources was the way to solve my issue.

avatar image ash21411 moghes · Jun 15, 2019 at 07:15 PM 0
Share

void ReadCSVFile(int j) { // StreamReader streamReader = new StreamReader(new $$anonymous$$emoryStream((Resources.Load("Assets/Resources/ashR3.csv") as TextAsset).bytes)); var instance = Resources.Load("Resources/ashR3.csv"); StreamReader streamReader = new StreamReader(new $$anonymous$$emoryStream((Resources.Load("Assets/Resources/ashR3.csv") as TextAsset).bytes));

Getting This Error

NullReferenceException: Object reference not set to an instance of an object readcsv.ReadCSVFile (System.Int32 j) (at Assets/readcsv.cs:26)

avatar image Kiichi · May 13, 2015 at 01:31 PM 0
Share

Glad to help you, thanks ^_^

avatar image
2

Answer by FWCorey · May 09, 2015 at 06:17 PM

Yes, you need to use a different path. From the documentation: //Data (this folder is read only, use Application.persistentDataPath to save data).

The docs say this is for iOS but the same limitation applies on Android IIRC. The standard data path is readonly. If you don't intend to edit the file at runtime, you are better off putting it in Resources and accessing it from there using Resources.Load(). Info in the docs is HERE

Comment
Add comment · Show 16 · 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 moghes · May 10, 2015 at 03:03 AM 0
Share

@FWCoreythanks for your answer. I know Application.dataPath is read only and I am reading only for that directory,

 streamReader = new StreamReader(File.OpenRead(Application.dataPath + fileName ));

and don't have a write function.

I have placed my files in a directory in the root folder besides the Resources folder.

Already I have my images placed in my resources and loading from there.

So do you mean something like?

 streamReader = new StreamReader(Resources.Load(fileName));
avatar image FWCorey · May 10, 2015 at 03:51 AM 0
Share

yep.. though IIRC the file needs to be renamed to have a .txt extension, even if it's binary.

avatar image moghes · May 11, 2015 at 09:44 PM 1
Share

@FWCorey I have located my files inside a folder in the root and that's dataPath, so do you now where to put them in order to read from persistentdataPath?

Also I got this error when running the app on an android device: IsolatedStorageException: Could not find a part of the path"/xxx/xxx/com.ccc.cccc/file.apk/$$anonymous$$yFolder/file.csv

many thanks

avatar image FWCorey · May 13, 2015 at 12:00 PM 1
Share

Docs for TextAsset are here: http://docs.unity3d.com/$$anonymous$$anual/class-TextAsset.html

avatar image FWCorey · May 13, 2015 at 12:05 PM 1
Share

Forgot it was UnityEngine.Object and not System.Object... The caveat with TextAsset is that it's readonly. If you want to edit the .csv at runtime you will need to generate a new text file in an accessible folder from the version in Resources then edit it from the new location.

Show more comments

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

21 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

Related Questions

How do you copy PersistentDataFolder between devices? 2 Answers

Why file creation on android is not working? 1 Answer

is it safe to save info in PlayerPrefs? 2 Answers

How to convert WWW type to FileStream? 1 Answer

File paths 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