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();
        }
    }
}
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号