Serialization Exception Error When Trying to Load

This is my first time posting so sorry for any obvious mistakes. I am attempting to save and load an integer, and it was working yesterday. The only thing I changed was attempting to save an array too, this didn’t work and I reverted back all the changes and am now getting an error. This is my code:

public int waveRecord;

public void Save() {
		BinaryFormatter formatter = new BinaryFormatter();
		FileStream playerFile = File.Create(Application.persistentDataPath + "/playerData.dat");
		PlayerStats stats = new PlayerStats();

		stats.waveRecord = waveRecord;
		playerFile.Close();
	}

	public void Load() {
		if(File.Exists(Application.persistentDataPath + "/playerData.dat")) {
			BinaryFormatter formatter = new BinaryFormatter();
			FileStream playerFile = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open);
			PlayerStats stats = (PlayerStats)formatter.Deserialize(playerFile);
			Debug.Log ("LOADED");
			playerFile.Close();

			waveRecord = stats.waveRecord;
		}
	}
}

[Serializable]
class PlayerStats {
	public int waveRecord;
}

The problem is when I attempt to load the game I get this error:

SerializationException: serializationStream supports seeking, but its length is 0

I have no idea what this means, and I have tried searching it but have found little help. It only happens on attempting to load the game, not saving it (which appears to work fine). I am not very experienced so would appreciate any suggestions, thanks.

edit: It appears the file is completely empty even after saving, which I am guessing is why it isn’t loading properly. Not sure why this is happening.

I found the problem. I must have accidentally deleted this line from the save when I made the edits:

formatter.Serialize(playerFile, stats);

It simply wasn’t saving properly, and since the file was empty then I was getting an error when I tried to load it.

Hi, I guess you didn’t call formater.serialize in your Save() function.