How save data file using System.IO ?
using UnityEngine;
using System.Collections;
using System.IO;
public class script : MonoBehaviour {
public string filetosave;
void Start()
{
if (filename == "") filename = "Assets/file.txt";
}
public void OnClick() //I use unity UI
{
using (StreamWriter writer = new StreamWriter(filetosave))
{
writer.WriteLine(); // line which I want to skip
writer.WriteLine("some data");
writer.Close();
}
}
}
How can I write data to the second line, so as not to overwrite the first, does not work that says you can not wrie anything (which is logical), how can I write a second line? cs used
Answer by Cris_2013 · Jan 31, 2020 at 08:57 PM
I know this post is old but just in case someone comes with the same problem.
just use writer.Write() and pass to the Write function any object you want to write in the file.
For example, string myString = "Hello";
writer.Write(myString);
and then to load use: reader.ReadString();
You can find more info on the msdn (which is really good for standard libraries): https://docs.microsoft.com/es-es/dotnet/api/system.io.streamwriter?view=netframework-4.8 https://docs.microsoft.com/es-es/dotnet/api/system.io.streamreader?view=netframework-4.8