C#中的StreamWriter
使用C#中的StreamWriter将字符写入流中。
使用StreamWriter,创建一个新文件-
StreamWriter sw = new StreamWriter("hello.txt"))将文本添加到文件-
sw.WriteLine("Hello");
sw.WriteLine("World");以下是代码-
示例
using System.IO;
public class Program {
public static void Main() {
using (StreamWriter sw = new StreamWriter("hello.txt")) {
sw.WriteLine("Hello");
sw.WriteLine("World");
}
}
}它创建文件“hello.text”并向其中添加文本-
输出结果
以下是输出。
Hello World
热门推荐
10 餐厅虎年贺卡祝福语简短
11 个性留言简短英文祝福语
12 简短的古风生日祝福语
13 寿宴祝福语蛋糕文案简短
14 开心早上祝福语简短英语
15 生日祝福语孙悟空简短
16 复古婚礼祝福语高级简短
17 如果不结婚祝福语简短
18 高考前放松祝福语简短