c#winform如何读取txt文件内容

qq_45227600 2019-06-16 11:16:57
怎样写入并读取TXT文件中的内容
...全文
584 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lionheart922 2019-06-19
  • 打赏
  • 举报
回复
和winform没关系,用System.IO这个命名空间下的类就能实现
华芸智森 2019-06-19
  • 打赏
  • 举报
回复
Using reader As StreamReader = File.OpenText("d:\a.txt") Dim s As String = reader.ReadToEnd() End Using
假正经的咸鱼 2019-06-19
  • 打赏
  • 举报
回复
//读取
public void Read(string path)
{
    StreamReader sr = new StreamReader();
    string line ;
    line = sr.ReadLine();
    while (line != null)
    {
        Console.WriteLine(line.ToString());
    }
}

//写入
public void Write(string path,string context)
{
    FileStream fs = new FileStream(path,FileMode.Create);
    byte[] data = System.Text.Encoding.Default.GetBytes(context);
    fs.Write(data,0,data.length);
    fs.Flush();
    fs.Close();
}
假正经的咸鱼 2019-06-19
  • 打赏
  • 举报
回复
读取文件: public void Read(string path) { }
wangmoxhn 2019-06-16
  • 打赏
  • 举报
回复
File.readalltext读取,file.writealltext写入

110,545

社区成员

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

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

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