I am using methods to serialize and de-serialize objects to binary file that I have found described and discussed here on stackoverflow. among others in following link: Pulling objects from binary file and putting in List<T> The serialisation process is working fine, I see the file growing when objects are appended to it and when reading with deserialization the problem is that I only get the part of the list that was written in the first write to file. The data retrieved seem correct, but I do not get to read beyond the first number of objects that were in the list in the first "write" operation. it is like the file position is always set to zero.
can the read operation be looped or controlled in any way to forced it to read the entire file?
Appreciate your comments on this
Thor
class singleBlob
{
public Bitmap bmpIndividualFish;
public Int64 idNumber;
public float area;
public float areaRatio;
}
class writeToFile
{
public void write( List<singleBlob> listOfBlobs)
{
string dir = @"D:\temp";
string serFileName = Path.Combine(dir, "fIndividualFish.bin");
//serialize
using (Stream streamw = File.Open(serFileName, FileMode.Append))
{
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bformatter.Serialize(streamw, listOfBlobs);
//streamw.Close();
}
}
public List<singleBlob> read()
{
string dir = @"D:\temp";
string serFileName = Path.Combine(dir, "fIndividualFish.bin");
//deserialize
using (Stream stream = File.Open(serFileName, FileMode.Open,FileAccess.Read))
{
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
List<singleBlob> listOfBlobs = (List<singleBlob>)bformatter.Deserialize(stream);
//stream.Close();
return listOfBlobs;
}
}