流的整个要点是,您不必将整个对象保存在内存中.你可以根据需要逐一阅读.
如果要附加到文件,则应使用File.AppendText哪个文件将创建StreamWriter附加到文件末尾的文件.
这是一个例子:
string path = @"c:\temp\MyTest.txt";
// This text is always added, making the file longer over time
// if it is not deleted.
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("This");
sw.WriteLine("is Extra");
sw.WriteLine("Text");
}
Run Code Online (Sandbox Code Playgroud)
同样,整个文件不会存储在内存中.
文档:http: //msdn.microsoft.com/en-us/library/system.io.file.appendtext.aspx
| 归档时间: |
|
| 查看次数: |
718 次 |
| 最近记录: |