读写txt文件_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 读写txt文件

读写txt文件

 2013/8/8 17:08:14  月嘿风高  博客园  我要评论(0)
  • 摘要:------------------------写txt文件---------------------------------stringfileName=Path.Combine(Application.StartupPath,@"History.txt");StreamWriterwriter=newStreamWriter(fileName,false,Encoding.Default);foreach(stringnameinthis.userName
  • 标签:文件

------------------------写txt文件---------------------------------
string fileName = Path.Combine(Application.StartupPath, @"History.txt");
StreamWriter writer = new StreamWriter(fileName,false,Encoding.Default);
foreach (string name in this.userName.AutoCompleteCustomSource)
{
writer.WriteLine(name);
}
writer.Flush();
writer.Close();

------------------------读txt文件---------------------------------
string fileName = Path.Combine(Application.StartupPath, @"History.txt");
if (File.Exists(fileName))
{
StreamReader reader = new StreamReader(fileName,Encoding.Default);
string name = reader.ReadLine();
while (name != null)
{
this.userName.AutoCompleteCustomSource.Add(name);
this.userName.Items.Add(name);
name = reader.ReadLine();
}
reader.Close();
}

发表评论
用户名: 匿名