- Home /
Storing large files locally
How do you store large files locally - PlayerPrefs seem limited to 1 MB?
Answer by Mox.du · Nov 02, 2011 at 05:23 AM
Hi,
have you tried system.IO - StreamWriter function?
Goes like this:
import System.IO; private var filePath : String; private var filename= "SavedGame"; private var extension = ".txt";
function Start () { filePath = Application.dataPath + "/"; print (filePath + filename+ extension); WriteFile(fileName); }
function WriteFile(fileName : String) { var sWrite: StreamWriter = new StreamWriter(filePath + filename + extension); sWrite.WriteLine("This is a test"); sWrite.WriteLine("We are in level " + Application.loadedLevel); sWrite.WriteLine("This will be some data"); sWrite.Flush(); sWrite.Close(); }
function ReadFile(fileName : String) { var sRead = new File.OpenText(filePath + fileName + extension); var input = ""; while (true) { input = sRead.ReadLine(); if (input == null) break; print ("Content: "+ input); } sRead.Close(); }
It seems that on FAT32 file systems StreamWriter has file size restriction around 4.2 GB.
Regards.
import http://System.IO;
?? By the way, the ~4GB limit is inherent to FAT32, not StreamWriter
.
Does this work on $$anonymous$$obile iOS or Android or is it Windows desktop only?
Answer by CHPedersen · Nov 02, 2011 at 10:38 AM
Correct, use [System.IO] libraries. Here are compatibility notes:
It works out of the box on desktop machines.
It does not work at all in webplayers due to security constraints.
It works on Android if you set up write permissions in the manifest file, see this link
It works on iPhone if you save files to a specifik Documents folder, see this link