25-C#笔记-文件的输入输出

1. 写txt

FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
F.WriteLine("Hello");
F.Write("Hello");
F.Close();

  

 

2. 读写txt

                using (StreamReader sr = new StreamReader(@"c:/jamaica.txt"))
                {
                    string line;
                   
                    // 从文件读取并显示行,直到文件的末尾 
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                }

  

参考:

http://www.runoob.com/csharp/csharp-file-io.html

 

posted @ 2018-05-21 22:44  路边的十元钱硬币  阅读(192)  评论(0编辑  收藏  举报