Dear sir
Thanks for your time. I have jus about tried everything but just cant seem to get this system to work.
What woulod be the best method to create, write and read a txt file on the ipad.
Thanx
Gordon Berrington
Dear sir
Thanks for your time. I have jus about tried everything but just cant seem to get this system to work.
What woulod be the best method to create, write and read a txt file on the ipad.
Thanx
Gordon Berrington
Check out Application.dataPath (or have you already done so and found it doesn’t work for you?)
Note: Application.dataPath doesn’t work on iPhone.
It is a readonly location and you cannot create files there. There is a Documents folder outside your app bundle that is a writeable location.
I use: Application.dataPath + “/…/…/Documents/” To reach it. This method will also place a Documents folder right outside of your project folder itself when inside the editor(nice if you have multiple versions of the same project you put them all in one folder and they all access the same documents folder).
Also you can use any of the .NET file writing utils to actually write it there.
Ntero, thanks. How would I script the path in JS if you could help me with the write to the position. Curently I`m trying this but its not working:
var writer : StreamWriter;
//FileInfo t = new FileInfo(_FileLocation+“\”+ _FileName);
var path = Application.dataPath.Substring (0, Application.dataPath.Length - 4)+“Documents”;
// Strip application name
try{
var sw = new StreamWriter(path+“/Player1.txt”);
for( var p =0;p<arr.length;++p) {
sw.WriteLine(arr[p]);
}
writer.Close();
Debug.Log(“File written.”);
}
catch(err){
print(“Blixem”);
}
Thanx for your advice, Im pretty knew to unity.
Gordon
Ntero, thanks. How would I script the path in JS if you could help me with the write to the position. Curently I`m trying this but its not working:
var writer : StreamWriter;
//FileInfo t = new FileInfo(_FileLocation+“\”+ _FileName);
var path = Application.dataPath.Substring (0, Application.dataPath.Length - 4)+“Documents”;
// Strip application name
try{
var sw = new StreamWriter(path+“/Player1.txt”);
for( var p =0;p<arr.length;++p) {
sw.WriteLine(arr[p]);
}
writer.Close();
Debug.Log(“File written.”);
}
catch(err){
print(“Blixem”);
}
Thanx for your advice, Im pretty knew to unity.
Gordon
I prefer C# immensly over JS, I don’t really use JS so I can’t really help you with syntax, but it looks ok.
Don’t use the Substring. Using Substring relies on a constant App name, and has the potential to break when you change the name of the app. You can use “/…/” to go backwards in the folder hierarchy and it becomes much more reusable/less error prone. Outside of that I use a FileStream instead of a StreamWriter, but the rest looks similar.
edit: so change path to
var path = Application.dataPath + “/…/…/Documents/”;
for a little less error prone Documents path retrieval. Then just append the Filename.extension to it and start writing with something like the FileStream class set to FileMode.Create.
Thanx a million Ntero. That was the problem. Appreciate your help. Working fine now.