初学c#,大家帮帮忙!
目的简单,就是点一个button,往txt里添加一条记录。可是,下面的程序怎么一直是覆盖记录啊……
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
try
{ FileStream aFile = new FileStream(@"D:\银行.txt", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine(textBox1.Text);
textBox1.Text = null;
sw.Close(); } catch (IOException e)
{ Console.WriteLine("An IO exception has been thrown!"); Console.WriteLine(e.ToString()); Console.ReadLine(); return; }
}
}
}
目的简单,就是点一个button,往txt里添加一条记录。可是,下面的程序怎么一直是覆盖记录啊……
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
try
{ FileStream aFile = new FileStream(@"D:\银行.txt", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine(textBox1.Text);
textBox1.Text = null;
sw.Close(); } catch (IOException e)
{ Console.WriteLine("An IO exception has been thrown!"); Console.WriteLine(e.ToString()); Console.ReadLine(); return; }
}
}
}
sw.WriteLine("AAA");
sw.WriteLine("BBB");
sw.Flush();
sw.Close();
{
sw.WriteLine(textBox1.Text);
}
{
sw.WriteLine(textBox1.Text);
}