• StreamWrite-StreamRead 读写文本文件


     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 //添加命名空间
     8 using System.IO;
     9 
    10 namespace 读取文本文件
    11 {
    12     class Program
    13     {
    14         static void Main(string[] args)
    15         {
    16              //读取
    17             using (StreamReader sr = new StreamReader(@"C:UsersAdministratorDesktop电影.txt", Encoding.Default))
    18             {
    19                 //Console.WriteLine(sr.ReadLine());
    20                 while (!sr.EndOfStream)
    21                 {
    22                     Console.WriteLine(sr.ReadLine());
    23                 }
    24             }
    25 
    26 
    27             //写入
    28             //true 代表是追加文本还是覆盖文本
    29             using (StreamWriter sw = new StreamWriter(@"C:UsersAdministratorDesktop
    ewnwe.txt", true))
    30             {
    31                 sw.Write("测试文本文段!");
    32             }
    33 
    34              Console.ReadKey();
    35         }
    36     }
    37 }
  • 相关阅读:
    006 date find
    005 输出重定向 > >>命令 echo命令 tail命令
    总结,一周,
    mokey 学习
    树状,
    定制,
    萌芽,
    到底为什么,
    会,
    “恋爱”,一路走来,
  • 原文地址:https://www.cnblogs.com/KTblog/p/4501902.html
Copyright © 2020-2023  润新知