读取:

1.使用StreamReader读取文件,然后一行一行的输出

  StreamReader sr = new StreamReader(path,Encoding.Default);
  String line;
  while ((line = sr.ReadLine()) != null)
  {
    Console.WriteLine(line.ToString());
  }

写入:

1. File.WriteAllText(filePath, str, Encoding.UTF8);  //filePath:txt文件地址。str:写入的字符串变量。注:如果文件已经存在则覆盖,不会报错。

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2023-01-25
  • 2021-04-17
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
猜你喜欢
  • 2021-10-05
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案