如何通过c#程序新建一个txt 文件,并对txt文件进行读和写?

mosuo 2003-08-08 03:27:12
如何通过c#程序新建一个txt 文件,并对txt文件进行读和写?
...全文
626 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xz_king 2003-10-14
  • 打赏
  • 举报
回复
差不多都说出来了。
rgbcn 2003-10-14
  • 打赏
  • 举报
回复
StreamWriter sw = File.CreateText(@"d:\a.txt");
sw.Write("hello");
sw.WriteLine("hello");
sw.Close()
wuyuzhuo2002 2003-08-08
  • 打赏
  • 举报
回复
用textRead吧最快,最简单
kuangren 2003-08-08
  • 打赏
  • 举报
回复
using System.IO;
class mainclass
{
static void Main()
{

string str;
string address="";
FileStream fs;

try
{
fs=new FileStream("hello.txt",FileMode.OpenOrCreate);
}
catch(FileNotFoundException ex)
{
MessageBox.Show("读取文件出现错误!"+ex.Message,"错误",0x00);
return;
}
StreamReader sr=new StreamReader(fs);

while((str=sr.ReadLine())!=null)
{
address=address+str;
}

sr.Close();
}
}
kuangren 2003-08-08
  • 打赏
  • 举报
回复
string str;
string address="";
FileStream fs;

try
{
fs=new FileStream("hello.txt",FileMode.OpenOrCreate);
}
catch(FileNotFoundException ex)
{
MessageBox.Show("读取文件出现错误!"+ex.Message,"错误");
return;
}
StreamReader sr=new StreamReader(fs);

while((str=sr.ReadLine())!=null)
{
address=address+str;
}

sr.Close();
administr 2003-08-08
  • 打赏
  • 举报
回复
加上RichTextBox控件
radioheads 2003-08-08
  • 打赏
  • 举报
回复
忘了写读
StreamReader sr = File.OpenText(@"d:\a.txt");
string str;
while((str = sr.ReadLine()) != null)
{
//...............
}
radioheads 2003-08-08
  • 打赏
  • 举报
回复
using System.IO;
radioheads 2003-08-08
  • 打赏
  • 举报
回复
StreamWriter sw = File.CreateText(@"d:\a.txt");
sw.Write("hello");
sw.WriteLine("hello");
sw.Close()

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧