-
// I am appending objects into a .dat file and i want to excess all
// the object one by onepublic void Submit() // for creating file
Name = inputName.text;
Country = inputCountry.text;
BinaryFormatter toBinary = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath+“/scoreSystem.dat”,FileMode.Append);
Score obj = new Score();
obj.Country = Country;
obj.Name = Name;
print(Name);toBinary.Serialize(file, obj); file.Close(); } public void Show() // for reading from file { if (File.Exists(Application.persistentDataPath + "/scoreSystem.dat")) { FileStream file = File.Open(Application.persistentDataPath + "/scoreSystem.dat",FileMode.Open); BinaryFormatter toBinary = new BinaryFormatter(); while (file.EndRead()) // what do i do //here in order to access all the //object { Score obj = (Score)toBinary.Deserialize(file); print(obj.Name); } file.Close(); }
Finally I got the answer that is simple :-
With FileStream file; you could do file.Position!=file.Length to detect EOF.