【文件属性】:
文件名称:txt文件写入读取.txt
文件大小:6KB
文件格式:TXT
更新时间:2012-11-16 05:26:54
txt文件写入读取.txt
private void inputdata_Click(object sender, EventArgs e)
{
string path1 = @"d:test1.txt";
string path2 = @"d:test2.txt";
//创建文件
if (!File.Exists(path1))
{
StreamWriter sw = File.CreateText(path1);
sw.WriteLine("write some text.");
sw.Close();
}
//打开文件
StreamReader sr = File.OpenText (path1);
string s = "";
while ((s = sr.ReadLine()) != null)
{
textBox1.Text = s;
}
sr.Close();