Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Dec 04, 2015 at 03:37 PM by laharl219 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by laharl219 · Dec 03, 2015 at 11:58 AM · c#androidjsondatapathwrite data

Help Writing and reading files on android.

Hello, recently i've been working on an app in witch i'll use Json files access my sql database.

I'm programing everyhink on C#, and using LitJson Plugin for Json files.

The code i need to fix is supposed to Write a Json file, then read it, but i think i micht be doing something wrong with the file directory of android....

i'm using:

         File.WriteAllText(Application.persistentDataPath + "/StreamingAssets/campoos.json", "[" + CamposData.ToString() + "]");    // To write my Json file
 
 
         CamposData = JsonMapper.ToObject(File.ReadAllText(Application.persistentDataPath + "/StreamingAssets/campoos.json")); // To read my Json file


The code was supposed to display some info of the Json file on screen. however, when on PC it works, but at Android devices i won't.

Comment
Add comment · Show 12
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 Bonfire-Boy · Dec 03, 2015 at 12:27 PM 1
Share

What do you mean when you say it "doesn't work"? Is it the writing or the reading? If it's the reading, is it the file IO or the Json$$anonymous$$apper conversion?

If you're not sure, you can try things like breaking the code down (eg the reading can be in 2 steps, read the file and then convert), adding checks and logging, and looking to see if the file's been created.

Also, what do the logs say? And does the directory you're trying to write to exist?

avatar image laharl219 Bonfire-Boy · Dec 03, 2015 at 12:46 PM 0
Share

I printed the persistent datapath on android, and looked for the file...couldn't find anything so i guess the writing isn't working ;/

Any idea on what to do?

avatar image isteffy laharl219 · Jul 27, 2016 at 01:28 PM 0
Share

How are you reading the Debug log while you phone is plugged into the GearVR?

avatar image laharl219 Bonfire-Boy · Dec 03, 2015 at 01:04 PM 0
Share

$$anonymous$$ade a few more checks, I'm pretty sure Writing is now working

avatar image saschandroid laharl219 · Dec 03, 2015 at 01:10 PM 1
Share

Documentation: "Note that on some platforms it is not possible to directly access the Strea$$anonymous$$gAssets folder because there is no file system access in the web platforms, and because it is compressed into the .apk file on Android. On those platforms, a url will be returned, which can be used using the WWW class."

Show more comments
Show more comments
avatar image laharl219 Bonfire-Boy · Dec 03, 2015 at 02:13 PM 0
Share

Related to your comment as i can't answer directly, i didn't check for the existence of Strea$$anonymous$$gAssets file, a simple detail i simply forgot about ;/

Thx for the Help ;D

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Dec 04, 2015 at 01:31 PM

The problem is that the StreamingAssets folder doesn't exist on android. The streaming assets are packed into the JAR / APK file and you have to use

 "jar:file://" + Application.dataPath + "!/assets/"

This works only with the WWW class as stated on the documentation page i've linked above. Of course you can't "write" to that "folder" since it's not a real folder. If you want to cache things in the persistentDataPath, you have to create any subfolders you like to use yourself. The persistentDataPath doesn't contain any subfolders by default.

The easiest way to create folders is to use the DirectoryInfo class.

Please don't close a question with "right answer selected" if there is no answer and of course no answer selected.

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

Follow this Question

Answers Answers and Comments

43 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

Related Questions

Android json read and write 1 Answer

Problem with Json and Android ! 0 Answers

Read and Write Textfile on mobile (C# Unity ) 0 Answers

Writing to the Externally Mounted SD Card Android 1 Answer

Json doesnt work in android (unity) 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