C#中如何读写文件,控制台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        public static void Main()
        {
            string[] s = { "c:\\", "d:\\", "e:\\", "f:\\" };
            using (StreamWriter sw = new StreamWriter("1.ini", false))
            //false为直接覆盖该文件,true就直接添加在文件末尾
            {
                foreach (string t in s)
                {
                    sw.WriteLine(t);
                }
            }
            using (StreamReader sr = new StreamReader("1.ini"))
            {
                String temp = "";
                string ss = sr.ReadLine();
                while (ss != null)
                {
                    temp += ss;
                    Console.WriteLine(temp);
                    ss = sr.ReadLine();
                }
            }
            Console.ReadLine();
        }
    }
}

posted @ 2012-12-24 17:40  Entropy_lxl  阅读(542)  评论(0编辑  收藏  举报