- Home /
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?
Answer by Sisso · Jun 27, 2014 at 01:09 AM
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");
}
Your answer
Follow this Question
Related Questions
How do I include a custom file in my build? 3 Answers
File Browser that works on ipad + samsung + desktop 0 Answers
Problem on writing the copied array of string on text pad 2 Answers
Can you monitor or profile file I/O from within Unity? 0 Answers
What to do about a Pixel crushers dialogue template file screw up? 0 Answers