Quantcast
Channel: Questions in topic: "file io"
Viewing all articles
Browse latest Browse all 10

Saving data files in iOS

$
0
0
Hi, I'm testing out iOS builds of my game, and the majority of my problems (so far!) seem to be to do with File IO. I've already fixed problems to do with accessing game files ([this thread][1] solved my problem), but now I'm having trouble creating user data files. From everything I've read so far, I understand that I should use the "/Documents" folder inside the app. So, here is my code: string savepath; if (Application.platform == RuntimePlatform.IPhonePlayer) { savepath = Application.dataPath.Replace ("/Data", "/Documents/"); } else { savepath = Application.dataPath; } ... var serializer = new XmlSerializer (typeof(Station)); var stream = new FileStream (savepath, FileMode.Create); serializer.Serialize (stream, this); stream.Close (); However, this throws the following DirectoryNotFoundException: > DirectoryNotFoundException: Could not find a part of the path "/var/mobile/Applications/5C190393-F75D-4CA5-89CA-17C8E42EF954/game.app/Documents/station.xml". at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0 at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in :0 The path looks as it should to me (the Documents folder should already exist in the app instance, I believe?), but I could be wrong. Any ideas? (I've tried FileMode.CreateNew as well as FileMode.Create). Any help would be appreciated, thanks! [1]: http://monotouch.2284126.n4.nabble.com/UnauthorizedAccessException-while-accessing-resources-td3952060.html

Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>