I am using the following code to save data to a file:
void save()
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open(Application.persistentDataPath + "/MyData.dat",FileMode.Append);
MyData data = new MyData ();
data.s = input.text;
input.text="";
bf.Serialize (file, data);
file.Close ();
}
And the following code to load data from the saved file:
public void load()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath+"/MyData.dat",FileMode.Open);
MyData data = (MyData)bf.Deserialize(file);
file.Close();
name = data.s; //returns only one string
}
[Serializable]
class MyData
{
public string s;
}
I am able to append multiple strings to a file, but when I am accessing them using
name = data.s;
it only returns a single string. Can anyone help me to sort out how ho print all the strings saved in the file.