C#streamwriter写文件
2010-11-21 15:59
246 查看
using System; using System.IO; class Test { public static void Main() { string path = @"c:/temp/MyTest.txt" ; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("Hello" ); sw.WriteLine("And" ); sw.WriteLine("Welcome" ); } } // 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" ); } // Open the file to read from. using (StreamReader sr = File.OpenText(path)) { string s = "" ; while ((s = sr.ReadLine()) != null ) { Console.WriteLine(s); } } } }
相关文章推荐
- c# 文件IO操作 StreamReader StreamWriter Split 使用
- c# 文件IO操作 StreamReader StreamWriter Split 使用
- C# SaveFileDialog +FileStream+StreamWriter 创建或者覆盖一个文件,并且写入
- C# 文件写入(StreamWriter),保存文件对话框(SaveFileDialog)
- C# FileStream分块读取和保存文件
- c#FileStream文件读写
- C#FileStream复制大文件【转自www.bitsCN.com】
- C#中的StreamReader/StreamWriter
- C# System.IO.FileStream 文件正由另一进程使用,因此该进程无法访问该文件
- C# StreamWriter 写入文本文件列的问题
- c#FileStream文件读写(转)
- 如何压缩多个文件/文件夹(GZipStream and C#)
- C#从文件读取 Stream
- C#StreamReader 读取Txt文件
- C# StreamReader/StreamWriter与FileStream用法详解
- c#针对文本文件之StreamRead和StreamWriter出现的理由
- c# Bitmap byte[] Stream 文件相互转换
- c#FileStream文件读写(转)
- FileStream读写文件 VS StreamWriter和StreamReader读写文件
- StreamWriter出现下面错误“正由另一进程使用,因此该进程无法访问该文件”