Reading/Writing to a text file on non-windows platforms

Hi, I’m writing a load/save system for my game, and as you can imagine I need to use text files. Well, I’m just about done with it, but there’s one little detail that I’ve been abstracting away for too long: reading and writing from a text file.

So, how should I go about reading/writing from/to a text file in Unity?

I’ve found plenty of solutions online, but they appear to use functions from Microsoft’s .Net platform(such as File.WriteLine(), etc.). This is fine-and-dandy on Windows platforms, but would these functions still work on other platforms? Say, for example, Android or the various consoles?

Further, where should I put my text files when I distribute the final game? Should I put them in different places for different platforms?

Yes, mono and unity abstract the platform specifics for you.

This code is safe to use in any platform that have access to a filesystem (not web)

var path = Application.persistentDataPath + "/data";
using (StreamWriter w = new StreamWriter(path)) {
	w.WriteLine("hello");
}