private void Form1_Load(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo myd = new DirectoryInfo(Application.StartupPath.ToString());
string str = myd.FullName.ToString()+@"\myfile.bin";
IFormatter formatter = new BinaryFormatter();
Stream stream =null; try
{
stream= new FileStream(str,FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
while(stream.Length!=0)
{
this.treeView1.Nodes.Add((TreeNode) formatter.Deserialize(stream));
}
}
catch(Exception e3)
{
MessageBox.Show(e3.Message);
}
finally
{
stream.Close();
}
}
private void button3_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo myd2 = new DirectoryInfo(Application.StartupPath.ToString());
myd2 = myd2.Parent;
string str = myd2.FullName.ToString()+@"\myfile.bin";
IFormatter formatter2 = new BinaryFormatter();
Stream stream2=null;
stream2 = new FileStream(str, FileMode.Append, FileAccess.Write, FileShare.None); foreach(TreeNode nodes in this.treeView1.Nodes)
{
try
{
formatter2.Serialize(stream2, nodes);
}
catch(Exception e4)
{
MessageBox.Show(e4.Message);
}
}
stream2.Close();
}
{
System.IO.DirectoryInfo myd = new DirectoryInfo(Application.StartupPath.ToString());
string str = myd.FullName.ToString()+@"\myfile.bin";
IFormatter formatter = new BinaryFormatter();
Stream stream =null; try
{
stream= new FileStream(str,FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
while(stream.Length!=0)
{
this.treeView1.Nodes.Add((TreeNode) formatter.Deserialize(stream));
}
}
catch(Exception e3)
{
MessageBox.Show(e3.Message);
}
finally
{
stream.Close();
}
}
private void button3_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo myd2 = new DirectoryInfo(Application.StartupPath.ToString());
myd2 = myd2.Parent;
string str = myd2.FullName.ToString()+@"\myfile.bin";
IFormatter formatter2 = new BinaryFormatter();
Stream stream2=null;
stream2 = new FileStream(str, FileMode.Append, FileAccess.Write, FileShare.None); foreach(TreeNode nodes in this.treeView1.Nodes)
{
try
{
formatter2.Serialize(stream2, nodes);
}
catch(Exception e4)
{
MessageBox.Show(e4.Message);
}
}
stream2.Close();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货