读文件:
1 StreamReader sr = new StreamReader(FileName, Encoding.Default);View Code
2 string content = "";
3 content = sr.ReadLine();
4
5 while (content != null)
6 {
7 //操作逻辑
8 ....
9 ....
10 content = sr.ReadLine();
11 }
12 sr.Close();
写文件:
1 string path = @"路径\list_key.txt";View Code
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();