I'm creating an app that should be accessable from every platform (android, IOS, windows). At this moment I'm saving a file that is set to a specific path. c:\test\test.exe. Now I know that Android and IOS don't have such directory. I was wondering if it was possible to save the file to a relative path? If not I might have to adapt the code that checks on what kind of device the app is running


If runningOnWindowsOS writefile(c:\test\test.txt)

if runningOnAndroid writefile(NOCLUE)

If runningOnIOS writefile(NOCLUEEITHER)

this is my code at the moment:

        string path = @"C:\test\test.txt";

        string createText = txt3.text + txtToLog + System.Environment.NewLine;

        File.WriteAllText(path, createText);

any clues on how to proceed with this

  • \$\begingroup\$ Small note, I should be able to read the file as well (or another not quite sure how it will go in the end). \$\endgroup\$
    – Budan18
    Nov 18, 2016 at 18:03

2 Answers 2


Utilize Unity's persistentDataPath.

Contains the path to the game data folder (Read Only).

This is path is platform specific.

  • \$\begingroup\$ Thank you just tested it out on my android device and my PC itself, it seems to work perfectly. Tests on IOS will follow soon, but I'm sure that will work to :) \$\endgroup\$
    – Budan18
    Nov 18, 2016 at 19:32
  • 2
    \$\begingroup\$ persistentDataPath might actually be what the OP is looking for. \$\endgroup\$
    – zcabjro
    Nov 19, 2016 at 1:34
  • \$\begingroup\$ Seconding @Jack. Since OP talks about saving, they probably want persistentDataPath. On some platforms, the game's installed location (dataPath) might not be writeable with the game's permissions, or might be overwritten when the game is updated, so it's recommend to store new files that you want to persist in persistentDataPath. \$\endgroup\$
    – DMGregory
    Nov 19, 2016 at 15:43
  • \$\begingroup\$ I've used persistentDataPath as i was reading the link Byte Gave me I figured that it would be best since I would also use IOS as dataPath is readOnly on that OS (as far as I remember). Thanks anyway :) \$\endgroup\$
    – Budan18
    Nov 19, 2016 at 22:13

I had had some problems with Loading of Json file from persistentDataPath and dataPath, so if you will have a problem like that - another solution is to write and load files from Resources folder that is Resources - it also allows you to load and write files and even specify a type of the file loaded Load.

Note: remember to use forward slashes - all Unity assets use them.

  • \$\begingroup\$ Not quite clear on how to use the path then, but at this moment i'm not having issues so it will do, thanks for the tip. And for the slashes, I noticed after 15 minutes struggling, but it's working perfectly now. \$\endgroup\$
    – Budan18
    Nov 19, 2016 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .