五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > C#使用StreamReader讀取打開文件和寫入文件的方法

C#使用StreamReader讀取打開文件和寫入文件的方法

文章來源:365jz.com     點(diǎn)擊數(shù):1004    更新時(shí)間:2017-08-19 09:59   參與評(píng)論

本文實(shí)例講述了C#使用StreamReader讀取文件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace W
{
  class Program
  {
    static void Main(string[] args)
    {
      using (StreamReader sr = new StreamReader (@"c:\1.txt",Encoding.UTF8,true))
      {
        while (!sr.EndOfStream)
        {
          Console.WriteLine(sr.ReadLine());
        }
      }
      Console.WriteLine("讀取完畢");
      Console.ReadKey();
    }
  }
}

本文實(shí)例講述了C#使用StreamWriter寫入文件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace W
{
  class Program
  {
    static void Main(string[] args)
    {
      using (StreamWriter sw = new StreamWriter (@"c:\1.txt",true,Encoding.UTF8))
      {
        for (int i = 0; i < 100; i++)
        {
          sw.WriteLine(i);
        }
      }
      Console.WriteLine("寫入完畢!");
    }
  }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答?。?點(diǎn)擊進(jìn)入論壇

發(fā)表評(píng)論 (1004人查看,0條評(píng)論)
請(qǐng)自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動(dòng)的言論。
昵稱:
最新評(píng)論
------分隔線----------------------------

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時(shí)間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號(hào)