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

猜你喜欢

转载自www.cnblogs.com/alexYuin/p/9069814.html