private void button3_Click(object sender, EventArgs e)
{
var obj = listBox1.Items.OfType().ToList();
FileStream fs = null;
try
{
string path = "c:\\hanhan.hqj";
if (string.IsNullOrEmpty(path)) return;
fs = new FileStream(path, FileMode.Create);
var bf = new BinaryFormatter();
fs.Position = 0;
bf.Serialize(fs, obj);
fs.Flush();
fs.Close();
}
catch (Exception ex)
{
if (fs != null) fs.Close();
}
}
private void button4_Click(object sender, EventArgs e)
{
FileStream fs = null;
try
{
string path = "c:\\hanhan.hqj";
if (string.IsNullOrEmpty(path)) return;
fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
var bf = new BinaryFormatter();
fs.Position = 0;
List xx = (List) bf.Deserialize(fs);
fs.Flush();
fs.Close();
listBox1.DataSource = xx;
}
catch (Exception ex)
{
if (fs != null) fs.Close();
}
}