StreamWriter和StremReader简单的用法

1                 string str = "中国";//写入的内容
2                 string path = @"e:\1.txt";//文件路径
3                 StreamWriter sw = new StreamWriter(path, true, Encoding.Unicode);
4                 sw.Write(str);
5                 sw.Close();
6                 Console.ReadKey();
View Code
 1  string path1 = @"e:\1.txt";//文件路径
 2                 FileStream fsFile = new FileStream(path1, FileMode.Open);
 3                 StreamReader srReader = new StreamReader(fsFile);
 4                 int iChar;
 5                 iChar = srReader.Read();
 6                 while (iChar != -1)
 7                 {
 8                     txbValue.Text += (Convert.ToChar(iChar));
 9                     iChar = srReader.Read();
10                 }
11                 srReader.Close();
View Code

 

posted @ 2015-05-06 15:32  Jbp  阅读(381)  评论(0编辑  收藏  举报