c# 文件的读写

    读文件:

 1 StreamReader sr = new StreamReader(FileName, Encoding.Default);
 2                 string content = "";
 3                 content = sr.ReadLine();
 4 
 5                 while (content != null)
 6                 {
 7                     //操作逻辑
 8                      ....
 9                      ....
10                     content = sr.ReadLine();
11                 }
12                 sr.Close();
View Code


 

   写文件:

 1             string path = @"路径\list_key.txt";
 2 
 3             FileStream fs1 = new FileStream(path, FileMode.Create, FileAccess.Write);
 4            //创建写入文件 
 5             StreamWriter sw1 = new StreamWriter(fs1, Encoding.Default);
 6             sw1.AutoFlush = true;
 7 
 8            // for (int i = 0; i < strFirstList.Count; i++)
 9            // {
10                // sw1.Write(strFirstList[i]);
11                // sw1.Write(" ");
12                // sw1.WriteLine(strSecList[i]);
13             // }
14 
15 
16             fs1.Close();
View Code

 

posted @ 2014-09-22 15:36  二哥(阿伟)  阅读(121)  评论(0编辑  收藏  举报